02.Oracle/DataBase2012. 9. 21. 03:19
반응형

오랔믈 pivot 기능

SELECT TO_CHAR(rgs_dt,'YYYYMMDD'),
              'TA_IPT_ICG_MNFT_MST' AS title,
              COUNT(mrn)            AS cnt
         FROM TA_IPT_ICG_MNFT_MST
        WHERE USE_FG = 'S'
        GROUP BY TO_CHAR(rgs_dt,'YYYYMMDD')
           UNION
       SELECT TO_CHAR(rgs_dt,'YYYYMMDD'),
              'TA_ICG_MNFT_MST' AS title,
              COUNT(mrn)        AS cnt
         FROM TA_ICG_MNFT_MST
        WHERE USE_FG = 'S'
        GROUP BY TO_CHAR(rgs_dt,'YYYYMMDD')

 

 

 

 

SELECT *
  FROM
       (SELECT TO_CHAR(rgs_dt,'YYYYMMDD'),
              'TA_IPT_ICG_MNFT_MST' AS title,
              COUNT(mrn)            AS cnt
         FROM TA_IPT_ICG_MNFT_MST
        WHERE USE_FG = 'S'
        GROUP BY TO_CHAR(rgs_dt,'YYYYMMDD')
           UNION
       SELECT TO_CHAR(rgs_dt,'YYYYMMDD'),
              'TA_ICG_MNFT_MST' AS title,
              COUNT(mrn)        AS cnt
         FROM TA_ICG_MNFT_MST
        WHERE USE_FG = 'S'
        GROUP BY TO_CHAR(rgs_dt,'YYYYMMDD')
       ) pivot (SUM(cnt) FOR title IN('TA_IPT_ICG_MNFT_MST','TA_ICG_MNFT_MST'))
ORDER BY 1

 

 

 

Posted by 1010