원본 출처 : http://www.gurubee.net/article/54382
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | WITH T AS ( SELECT 'A' COL1, 6 COL2, 40 COL3 FROM DUAL UNION ALL SELECT 'A' , 6 , 20 FROM DUAL UNION ALL SELECT 'B' , 1 , 2 FROM DUAL UNION ALL SELECT 'B' , 1 , 2 FROM DUAL ) SELECT DECODE(1 , GROUPING(COL1), '총합계' , GROUPING(ROWNUM), COL1 || '중간합계' , COL1) COL , COL1 , SUM(COL2) COL2 , SUM(COL3) COL3 FROM T GROUP BY ROLLUP(COL1, ROWNUM) ORDER BY GROUPING(T.COL1) DESC -- 총합계를 위로 , COL1 , GROUPING(ROWNUM) -- 중간합계를 아래로 , ROWNUM ; | cs |
반응형