|
WITH salary AS ( SELECT '총무부' DEPT, '저미주' NAME, '01' SMONTH, 100000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '저미주' NAME, '02' SMONTH, 115000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '저미주' NAME, '03' SMONTH, 112000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '강모리' NAME, '07' SMONTH, 510000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '강모리' NAME, '08' SMONTH, 450000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '강모리' NAME, '09' SMONTH, 610000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '구하라' NAME, '05' SMONTH, 210000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '구하라' NAME, '06' SMONTH, 210000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '구하라' NAME, '07' SMONTH, 210000 SALARY FROM dual UNION ALL SELECT '총무부' DEPT, '구하라' NAME, '08' SMONTH, 210000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '구하라' NAME, '01' SMONTH, 200000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '구하라' NAME, '02' SMONTH, 210000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '구하라' NAME, '03' SMONTH, 230000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '구하라' NAME, '04' SMONTH, 230000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '이주리' NAME, '01' SMONTH, 150000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '이주리' NAME, '02' SMONTH, 160000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '이주리' NAME, '03' SMONTH, 170000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '저미주' NAME, '04' SMONTH, 112000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '저미주' NAME, '05' SMONTH, 112000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '저미주' NAME, '06' SMONTH, 112000 SALARY FROM dual UNION ALL SELECT '인사부' DEPT, '저미주' NAME, '07' SMONTH, 112000 SALARY FROM dual ) SELECT DEPT, NAME, COUNT(SMONTH) CNT, SUM(SALARY) SALARY , GROUPING(DEPT) G_DEPT, GROUPING(NAME) G_NAME , GROUPING(DEPT) + GROUPING(NAME) G_SUM , GROUPING_ID(DEPT, NAME) GING_ID , GROUP_ID() G_ID FROM salary WHERE SMONTH BETWEEN '01' AND '12' GROUP BY CUBE(DEPT, NAME) --GROUP BY ROLLUP(DEPT, NAME) ORDER BY GROUPING(DEPT), DEPT, GROUPING(NAME), NAME ;
DEPT NAME CNT SALARY G_DEPT G_NAME G_SUM GING_ID G_ID ------------------------------------------------------------------------- 인사부 구하라 4 870000 0 0 0 0 0 인사부 이주리 3 480000 0 0 0 0 0 인사부 저미주 4 448000 0 0 0 0 0 인사부 11 1798000 0 1 1 1 0 총무부 강모리 3 1570000 0 0 0 0 0 총무부 구하라 4 840000 0 0 0 0 0 총무부 저미주 3 327000 0 0 0 0 0 총무부 10 2737000 0 1 1 1 0 강모리 3 1570000 1 0 1 2 0 구하라 8 1710000 1 0 1 2 0 이주리 3 480000 1 0 1 2 0 저미주 7 775000 1 0 1 2 0 21 4535000 1 1 2 3 0
|