이런 Query로 혹시 Tuning이 가능할까요? 0 4 1,728

by 자바천재 [SQL Query] [2015.11.25 09:31:10]


한사람당 9줄의 정보가 나옵니다

그리구 전달 16일부터 해당달의 31일까지 데이터를 조회합니다

아무리해도 속도가 나질 않네요 현재 SQL 돌리는데만 1분이상 걸림으로 화면에서는 거의 Loading되는데 5분정도가 걸립니다

Tuning이 가능할까요?

감사합니다

 

 

 

WITH T1 AS (
        SELECT A.YYYY
            , A.MM
            , A.EMPNO
            , A.WORKDATE
            , D.JOB_NO
            ,C.NAME AS EMP_NAME
            ,D.DEPT
            ,D.CATETYPEDETCD
             , DECODE(B.NO, 1, ACTIN,  2, ACTOUT, 3, CALCIN, 4, CALCOUT, 5,TOTHRS, 6, REGHRS, 7, REGOT, 8, ESTOT, 9, REQOT) AMT
              , DECODE(B.NO, 1, 'ACTUAL IN',  2, 'ACTUAL OUT', 3, 'CALC. IN', 4, 'CALC. OUT', 5, 'TOTAL HRS', 6, 'REGULAR HRS', 7, 'REGULAR OT', 8,'EST. OT', 9, 'REQ. OT')  GUBUN
               , DECODE(B.NO, 1,1,  2, 2, 3, 3, 4,4, 5, 5, 6, 6, 7, 7, 8,8, 9, 9)  SORTORDER
               , A.REQOT
               , A.REGHRS
               , A.VADAY
               , A.REGOT
          FROM HR_PAYR_CUTOFF_TIME A
             , (SELECT LEVEL NO FROM DUAL CONNECT BY LEVEL <= 9) B
             , HR_INSA_MAST C
             , HR_PAYR_CUTOFF_EMP D
             ,  HR_DEPT_CODE E
          WHERE A.EMPNO = C.EMPNO
          AND    A.YYYY = D.YYYY
          AND    A.MM   = D.MM
          AND    A.EMPNO = D.EMPNO
          AND    A.JOB_NO = D.JOB_NO
          AND   D.DEPT = E.DEPT
          AND    A.YYYY = :YYYY
          AND    A.MM   = :MM
          AND    D.JOB_NO = :JOB_NO
        AND   (C.EMPNO LIKE '%' || UPPER(:EMPNO) || '%' OR C.NAME LIKE '%' || UPPER(:EMPNO) || '%' )
        AND (:CATETYPEDETCD IS NULL OR D.CATETYPEDETCD = :CATETYPEDETCD)     
        AND (:NATCD IS NULL OR D.NATCD = :NATCD)    
)
SELECT  
         (C.REGOT  + C.REQOT) AS REQOT
         , B.REGHRS
         , A.*
         ,O.NAME_ABBR AS DEPT_NAME
FROM (SELECT T1.YYYY, T1.MM, T1.EMPNO, T1.GUBUN, T1.SORTORDER, T1.JOB_NO, T1.EMP_NAME, T1.DEPT,T1.CATETYPEDETCD
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '16' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '16'                                                                       THEN AMT
                         END) PRE_16
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '17' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '17'                                                                       THEN AMT
                         END) PRE_17
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '18' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '18'                                                                       THEN AMT
                         END) PRE_18    
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '19' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '19'                                                                       THEN AMT
                         END) PRE_19
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '20' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '20'                                                                       THEN AMT
                         END) PRE_20
        , MIN(CASE WHEN WORKDATE   = :PRE_YYYYMM || '21' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :PRE_YYYYMM || '21'                                                                       THEN AMT
                         END) PRE_21
        , MIN(CASE WHEN WORKDATE   = :PRE_YYYYMM || '22' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '22'                                                                       THEN AMT
                         END) PRE_22
        , MIN(CASE WHEN WORKDATE   = :PRE_YYYYMM || '23' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '23'                                                                       THEN AMT
                         END) PRE_23
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '24' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '24'                                                                       THEN AMT
                         END) PRE_24
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '25' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '25'                                                                       THEN AMT
                         END) PRE_25
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '26' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '26'                                                                       THEN AMT
                         END) PRE_26
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '27' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '27'                                                                       THEN AMT
                         END) PRE_27
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '28' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '28'                                                                       THEN AMT
                         END) PRE_28
        , MIN(CASE WHEN WORKDATE   = :PRE_YYYYMM || '29' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '29'                                                                       THEN AMT
                         END) PRE_29
        , MIN(CASE WHEN WORKDATE   =  :PRE_YYYYMM || '30' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   =  :PRE_YYYYMM || '30'                                                                       THEN AMT
                         END) PRE_30
        , MIN(CASE WHEN WORKDATE   = :PRE_YYYYMM || '31' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :PRE_YYYYMM || '31'                                                                       THEN AMT
                         END) PRE_31
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '01' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '01'                                                                       THEN AMT
                         END) CUR_01
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '02' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '02'                                                                       THEN AMT
                         END) CUR_02
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '03' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '03'                                                                       THEN AMT
                         END) CUR_03
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '04' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '04'                                                                       THEN AMT
                         END) CUR_04
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '05' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '05'                                                                       THEN AMT
                         END) CUR_05
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '06' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '06'                                                                       THEN AMT
                         END) CUR_06
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '07' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '07'                                                                       THEN AMT
                         END) CUR_07
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '08' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '08'                                                                       THEN AMT
                         END) CUR_08
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '09' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '09'                                                                       THEN AMT
                         END) CUR_09
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '10' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '10'                                                                       THEN AMT
                         END) CUR_10
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '11' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '11'                                                                       THEN AMT
                         END) CUR_11
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '12' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '12'                                                                       THEN AMT
                         END) CUR_12
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '13' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '13'                                                                       THEN AMT
                         END) CUR_13
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '14' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '14'                                                                       THEN AMT
                         END) CUR_14
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '15' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '15'                                                                       THEN AMT
                         END) CUR_15
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '16' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '16'                                                                       THEN AMT
                         END) CUR_16
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '17' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '17'                                                                       THEN AMT
                         END) CUR_17
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '18' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '18'                                                                       THEN AMT
                         END) CUR_18
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '19' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '19'                                                                       THEN AMT
                         END) CUR_19
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '20' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '20'                                                                       THEN AMT
                         END) CUR_20
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '21' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '21'                                                                       THEN AMT
                         END) CUR_21
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '22' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '22'                                                                       THEN AMT
                         END) CUR_22
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '23' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '23'                                                                       THEN AMT
                         END) CUR_23       
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '24' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '24'                                                                       THEN AMT
                         END) CUR_24
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '25' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '25'                                                                       THEN AMT
                         END) CUR_25
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '26' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '26'                                                                       THEN AMT
                         END) CUR_26
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '27' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '27'                                                                       THEN AMT
                         END) CUR_27
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '28' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '28'                                                                       THEN AMT
                         END) CUR_28
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '29' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '29'                                                                       THEN AMT
                         END) CUR_29
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '30' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '30'                                                                       THEN AMT
                         END) CUR_30
        , MIN(CASE WHEN WORKDATE   = :YYYY || :MM || '31' AND VADAY = 1 AND GUBUN = 'REGULAR HRS' THEN 'V' 
                         WHEN WORKDATE   = :YYYY || :MM || '31'                                                                       THEN AMT
                         END) CUR_31
    FROM T1
     GROUP BY T1.YYYY, T1.MM, T1.EMPNO, T1.GUBUN, T1.SORTORDER, T1.JOB_NO, T1.EMP_NAME, T1.DEPT,T1.CATETYPEDETCD
   ) A
   , (SELECT SUM( NVL(DECODE(SORTORDER, 6, T1.REGHRS),0) ) AS REGHRS
               ,T1.YYYY, T1.MM, T1.JOB_NO, T1.EMPNO
     FROM T1
     WHERE T1.WORKDATE LIKE :YYYY || :MM || '%'
     GROUP BY  T1.YYYY, T1.MM, T1.JOB_NO, T1.EMPNO
  ) B
   , (SELECT SUM( NVL(DECODE(SORTORDER, 9, T1.REQOT),0) ) AS REQOT
                ,SUM( NVL(DECODE(SORTORDER, 9, T1.REGOT),0) ) AS REGOT
               ,T1.YYYY, T1.MM, T1.JOB_NO, T1.EMPNO
     FROM T1
     WHERE T1.WORKDATE BETWEEN  :PRE_YYYYMM || '16' AND  :YYYY || :MM || '20'
     GROUP BY  T1.YYYY, T1.MM, T1.JOB_NO, T1.EMPNO
  ) C 
   , (SELECT SUM( NVL(DECODE(SORTORDER, 9, T1.REGOT),0) ) AS REGOT
               ,T1.YYYY, T1.MM, T1.JOB_NO, T1.EMPNO
     FROM T1
     WHERE T1.WORKDATE BETWEEN  :PRE_YYYYMM || '16' AND  :YYYY || :MM || '20'
     GROUP BY  T1.YYYY, T1.MM, T1.JOB_NO, T1.EMPNO
  )   D
  , HR_DEPT_CODE O
WHERE A.YYYY = B.YYYY
AND     A.MM = B.MM
AND     A.JOB_NO = B.JOB_NO
AND     A.EMPNO = B.EMPNO
AND      A.YYYY = C.YYYY
AND     A.MM = C.MM
AND     A.JOB_NO = C.JOB_NO
AND     A.EMPNO = C.EMPNO
AND      A.YYYY = D.YYYY
AND     A.MM = D.MM
AND     A.JOB_NO = D.JOB_NO
AND     A.EMPNO = D.EMPNO
AND     A.DEPT    = O.DEPT
ORDER BY O.DEPT_SRL, A.EMP_NAME, A.SORTORDER

by 아발란체 [2015.11.25 10:23:12]

튜닝은 쿼리만 가지고 힘듭니다. 사용된 모든 테이블 인덱스 정보와 플랜이 필요합니다.

쿼리만 대충 보면 스칼라 서브 쿼리를 무분별하게 사용한 것 같습니다. 스칼라 서브 쿼리 효과가 발생하지 않는 구조는 오히려 속도가 느려집니다. 또한 총 결과 건수가 어떻게 되나요?


by 아발란체 [2015.11.25 15:56:53]

죄송합니다. 눈이 ㅠㅠ ... 스칼라가 아니라 인라인뷰 위치군용..


by 마농 [2015.11.25 14:41:22]
WITH t1 AS
(
SELECT a.yyyy
     , a.mm
     , a.empno
     , a.workdate
     , d.job_no
     , c.name AS emp_name
     , d.dept
     , d.catetypedetcd
     , e.name_abbr AS dept_name
     , e.dept_srl
     , DECODE(b.no, 1, a.actin
                  , 2, a.actout
                  , 3, a.calcin
                  , 4, a.calcout
                  , 5, a.tothrs
                  , 6, DECODE(a.vaday, 1, 'V', a.reghrs)
                  , 7, a.regot
                  , 8, a.estot
                  , 9, a.reqot
                  ) amt
     , DECODE(b.no, 1, 'ACTUAL IN'
                  , 2, 'ACTUAL OUT'
                  , 3, 'CALC. IN'
                  , 4, 'CALC. OUT'
                  , 5, 'TOTAL HRS'
                  , 6, 'REGULAR HRS'
                  , 7, 'REGULAR OT'
                  , 8, 'EST. OT'
                  , 9, 'REQ. OT'
                  ) gubun
     , b.no sortorder
     , DECODE(b.no, 6, a.reghrs) reghrs
     , DECODE(b.no, 9, a.regot + a.reqot) reqot
  FROM hr_payr_cutoff_time a
     , (SELECT LEVEL no FROM dual CONNECT BY LEVEL <= 9) b
     , hr_insa_mast c
     , hr_payr_cutoff_emp d
     , hr_dept_code e
 WHERE a.empno  = c.empno
   AND a.yyyy   = d.yyyy
   AND a.mm     = d.mm
   AND a.empno  = d.empno
   AND a.job_no = d.job_no
   AND d.dept   = e.dept
   AND (a.yyyy, a.mm) IN ( (:yyyy, :mm)
                         , (SUBSTR(:pre_yyyymm, 1, 4), SUBSTR(:pre_yyyymm, 5))
                         )
   AND a.workdate >= :pre_yyyymm||'16'
   AND d.job_no = :job_no
   AND (c.empno LIKE '%'||UPPER(:empno)|'%' OR c.name LIKE '%'||UPPER(:empno)||'%')
   AND (:catetypedetcd IS NULL OR d.catetypedetcd = :catetypedetcd)
   AND (:natcd IS NULL OR d.natcd = :natcd)
)
SELECT SUM(reqot ) reqot
     , SUM(reghrs) reghrs
     , yyyy
     , mm
     , empno
     , gubun
     , sortorder
     , job_no
     , emp_name
     , dept
     , catetypedetcd
     , MIN(DECODE(workdate, :pre_yyyymm||'16', amt)) pre_16
     , MIN(DECODE(workdate, :pre_yyyymm||'17', amt)) pre_17
     , MIN(DECODE(workdate, :pre_yyyymm||'18', amt)) pre_18
     , MIN(DECODE(workdate, :pre_yyyymm||'19', amt)) pre_19
     , MIN(DECODE(workdate, :pre_yyyymm||'20', amt)) pre_20
     , MIN(DECODE(workdate, :pre_yyyymm||'21', amt)) pre_21
     , MIN(DECODE(workdate, :pre_yyyymm||'22', amt)) pre_22
     , MIN(DECODE(workdate, :pre_yyyymm||'23', amt)) pre_23
     , MIN(DECODE(workdate, :pre_yyyymm||'24', amt)) pre_24
     , MIN(DECODE(workdate, :pre_yyyymm||'25', amt)) pre_25
     , MIN(DECODE(workdate, :pre_yyyymm||'26', amt)) pre_26
     , MIN(DECODE(workdate, :pre_yyyymm||'27', amt)) pre_27
     , MIN(DECODE(workdate, :pre_yyyymm||'28', amt)) pre_28
     , MIN(DECODE(workdate, :pre_yyyymm||'29', amt)) pre_29
     , MIN(DECODE(workdate, :pre_yyyymm||'30', amt)) pre_30
     , MIN(DECODE(workdate, :pre_yyyymm||'31', amt)) pre_31
     , MIN(DECODE(workdate,  :yyyy||:mm||'01', amt)) cur_01
     , MIN(DECODE(workdate,  :yyyy||:mm||'02', amt)) cur_02
     , MIN(DECODE(workdate,  :yyyy||:mm||'03', amt)) cur_03
     , MIN(DECODE(workdate,  :yyyy||:mm||'04', amt)) cur_04
     , MIN(DECODE(workdate,  :yyyy||:mm||'05', amt)) cur_05
     , MIN(DECODE(workdate,  :yyyy||:mm||'06', amt)) cur_06
     , MIN(DECODE(workdate,  :yyyy||:mm||'07', amt)) cur_07
     , MIN(DECODE(workdate,  :yyyy||:mm||'08', amt)) cur_08
     , MIN(DECODE(workdate,  :yyyy||:mm||'09', amt)) cur_09
     , MIN(DECODE(workdate,  :yyyy||:mm||'10', amt)) cur_10
     , MIN(DECODE(workdate,  :yyyy||:mm||'11', amt)) cur_11
     , MIN(DECODE(workdate,  :yyyy||:mm||'12', amt)) cur_12
     , MIN(DECODE(workdate,  :yyyy||:mm||'13', amt)) cur_13
     , MIN(DECODE(workdate,  :yyyy||:mm||'14', amt)) cur_14
     , MIN(DECODE(workdate,  :yyyy||:mm||'15', amt)) cur_15
     , MIN(DECODE(workdate,  :yyyy||:mm||'16', amt)) cur_16
     , MIN(DECODE(workdate,  :yyyy||:mm||'17', amt)) cur_17
     , MIN(DECODE(workdate,  :yyyy||:mm||'18', amt)) cur_18
     , MIN(DECODE(workdate,  :yyyy||:mm||'19', amt)) cur_19
     , MIN(DECODE(workdate,  :yyyy||:mm||'20', amt)) cur_20
     , MIN(DECODE(workdate,  :yyyy||:mm||'21', amt)) cur_21
     , MIN(DECODE(workdate,  :yyyy||:mm||'22', amt)) cur_22
     , MIN(DECODE(workdate,  :yyyy||:mm||'23', amt)) cur_23
     , MIN(DECODE(workdate,  :yyyy||:mm||'24', amt)) cur_24
     , MIN(DECODE(workdate,  :yyyy||:mm||'25', amt)) cur_25
     , MIN(DECODE(workdate,  :yyyy||:mm||'26', amt)) cur_26
     , MIN(DECODE(workdate,  :yyyy||:mm||'27', amt)) cur_27
     , MIN(DECODE(workdate,  :yyyy||:mm||'28', amt)) cur_28
     , MIN(DECODE(workdate,  :yyyy||:mm||'29', amt)) cur_29
     , MIN(DECODE(workdate,  :yyyy||:mm||'30', amt)) cur_30
     , MIN(DECODE(workdate,  :yyyy||:mm||'31', amt)) cur_31
     , dept_name
  FROM t1
 GROUP BY yyyy, mm, empno, gubun, sortorder, job_no, emp_name, dept, catetypedetcd
        , dept_name, dept_srl
 ORDER BY dept_srl, emp_name, sortorder
;

 


by 자바천재 [2015.11.25 16:05:46]

두분께 감사드립니다

특히 마농님은 그냥 수정해서 만드신데 대해서 감탄이 나올뿐입니다

그런데 제가 칼럼의 수만큼(9개)을 row로 내리기 위해서 connect by를 사용했는데

그냥 UNION ALL로 하니깐 속도가 더 빠르네요(Query는 훨씬 길어졌지만요)

데이터는 약 500만건에서 20만건을 추출해서 보여주는 겁니다

 

다시한번 감사드립니다

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입