SELECT *
FROM (
WITH TEST AS (
SELECT 'A' AS PRODUCT, 1 CNT, '1월' AS MON FROM DUAL UNION ALL
SELECT 'B' AS PRODUCT, 2 CNT, '2월' AS MON FROM DUAL UNION ALL
SELECT 'C' AS PRODUCT, 3 CNT, '3월' AS MON FROM DUAL UNION ALL
SELECT 'A' AS PRODUCT, 4 CNT, '2월' AS MON FROM DUAL UNION ALL
SELECT 'B' AS PRODUCT, 5 CNT, '2월' AS MON FROM DUAL UNION ALL
SELECT 'C' AS PRODUCT, 6 CNT, '4월' AS MON FROM DUAL UNION ALL
SELECT 'C' AS PRODUCT, 4 CNT, '4월' AS MON FROM DUAL
)
SELECT *
FROM (
(SELECT PRODUCT, CNT, MON, '실적' AS TYPE FROM TEST)
PIVOT( SUM(CNT) FOR MON IN ('1월', '2월', '3월', '4월'))
)
UNION ALL
SELECT 'A' AS PRODUCT, '목표' TYPE, 1 AS "1월", 1 AS "2월", 1 AS "3월", 1 AS "4월" FROM DUAL
)
ORDER BY PRODUCT, TYPE;
'ORACLE'에 해당되는 글 7건
- 2016.05.12 PIVOT 활용기...
ORACLE2016. 5. 12. 11:21