'oracle pivot 데이터를 가로를 세로로...'에 해당되는 글 1건

  1. 2012.09.21 oracle pivot 데이터를 가로를 세로로...
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