database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
ㆍPostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
PostgreSQL Q&A 8519 게시물 읽기
No. 8519
쿼리문좀 봐주세요 T.T 거북이 보다 더 느립니다.
작성자
이기자
작성일
2009-10-08 10:59ⓒ
2009-10-08 11:00ⓜ
조회수
7,603


보기 어려우시면, 죄송하지만 복사해서 워드패드나 메모장으로 보세요.


테이블 : t_sugangsave -> | 수강생코드 | 수강연번 | 수강대분류코드 | 중분류코드 | 과목코드 | 시작일 | 종료일 | ...
     t_sugangsave_gita ->  | 수강생코드 | 수강연번 | 신청한과목(ex.국어,영어...)  | ...
     t_student -> 학생정보.
이렇구요.

기간별, 과목별(대분류,중분류,과목코드)로 수강내역을 조회해서 그 과목(들)을 기간내에 수강한 학생의
정보를 한명당 한번씩만 보여줄려고합니다.

수강생이 수강항 목록 테이블 t_sugangsave와 목록을 하나의 레코드 t_sugangsave_gita를 조회해서
기간별, 과목별(대분류,중분류,과목코드)로
t_sugangsave 의 대분류(g_jjdc) 중분류(j_jjdc) 과목(m_jjdc)을 수강한 학생의 정보를 한번씩만 표시할려고합니다.
쿼리능력의 한계로 너무 난잡한데,
알아보실지 모르겠습니다. T.T;

SELECT a.stu_c,
   st.stu_n,
   (substring(a.yb,1,4)||'-'||substring(a.yb,5,4))as yb,
   case length(coalesce(st.ptel,''))
    when 11 then (substr(st.ptel,1,3)||'-'||substr(st.ptel,4,4)||'-'||substr(st.ptel,8,4))
    when 10 then (substr(st.ptel,1,3)||'-'||substr(st.ptel,4,3)||'-'||substr(st.ptel,7,4))
    when 8 then (substr(st.ptel,1,4)||'-'||substr(st.ptel,5,4))
    when 7 then (substr(st.ptel,1,3)||'-'||substr(st.ptel,4,4))
    else '' end as tel,
   coalesce(a.so_j,0)+ coalesce(a.so_d,0)as geum,
   a.deung_day,
   (case coalesce(a.msin_text,'')when''then''else'종합:'||a.msin_text end ||
    case coalesce(a.dan_sin_text,'')when''then''else' 단과:'||a.dan_sin_text end)as disp_sin,
   (select min(b.dan_date1) from t_sugangsave b
    where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb)as gigan,
    (select max(b.dan_date2) from t_sugangsave b
    where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb)as gigan2,
   case coalesce(a.j_jjdn,'')when''then'단과'else
    case coalesce(a.dan_sin_text,'')when''then a.j_jjdn else '단과/'|| a.j_jjdn end end as j_jjdn,
   0 as chk
    FROM t_sugangsave_gita a left outer join
   t_student st on st.mid=a.mid and st.stu_c=a.stu_c
 Where a.mid=:ag_mid and
   ( ((select min(b.dan_date1) from t_sugangsave b
     where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb) between '20080101' and '20091010') or
     ((select min(b.dan_date2) from t_sugangsave b
     where b.mid=a.mid and b.stu_c=a.stu_c and b.yb=a.yb) between '20080101' and '20091010')) and

   (:ag_g_jjdc_g=''or(select max(s1.g_jjdc) from t_sugangsave s1                                      <--  특히 이부분부터 매개변수값이 :ag_g_jjdc_g='', :ag_j_jjdc_g=''..이면
          where s1.mid=a.mid and s1.yb=a.yb and                                                                     그나마 빠른데, In일경우 엄청나게 느립니다.
            coalesce(s1.cancel,'')<>'Y' and s1.g_jjdc in(:ag_g_jjdc))in(:ag_g_jjdc))and                                                               
   (:ag_j_jjdc_g=''or(select max(s2.j_jjdc) from t_sugangsave s2
          where s2.mid=a.mid and s2.yb=a.yb and
            coalesce(s2.cancel,'')<>'Y' and s2.j_jjdc in(:ag_j_jjdc))in(:ag_j_jjdc))and
   (:ag_m_jjdc_g=''or(select max(s3.m_jjdc) from t_sugangsave s3
          where s3.mid=a.mid and s3.yb=a.yb and
            coalesce(s3.cancel,'')<>'Y' and s3.m_jjdc in(:ag_m_jjdc))in(:ag_m_jjdc))


조회 시간이 너무 오래걸려서 문제가 심각합니다.
쿼리문 손좀 봐주세요. T.T ;

이 글에 대한 댓글이 총 3건 있습니다.

explain analyze 결과도 보여주시면 좀더 조언을 얻을수 있을듯 합니다

그냥님이 2009-10-08 11:08에 작성한 댓글입니다. Edit

죄송합니다. 제가워낙 초보라서요. T.T ;
explain analyze 결과를 어디서 어떻게 봐야되죠?
windows용으로 사용중입니다.

이기자님이 2009-10-08 11:24에 작성한 댓글입니다. Edit

쿼리문 앞에 EXPLAIN ANALYZE 라고 덧붙이시기만 하면 됩니다. :)


explain analyze SELECT * FROM dept;

요렇게요.

SHK(rusion)님이 2009-10-08 12:29에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
8522속도 [2]
eee
2009-10-09
7108
8521아래 쿼리 속도 문제.. [4]
이기자
2009-10-08
7511
8520아래 쿼리의 EXPLAIN. [3]
이기자
2009-10-08
7238
8519쿼리문좀 봐주세요 T.T 거북이 보다 더 느립니다. [3]
이기자
2009-10-08
7603
8518연달아서 질문입니다 ㅡ,.ㅡ [1]
초보자
2009-10-06
6728
8517PostgreSQL 초보적인 질문입니다.. [2]
초보자
2009-10-06
10817
8516- [3]
아무개
2009-10-05
6770
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.022초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다