WITH TEST AS (
SELECT '1' CLASS, 'ACCOUNTING' DNAME,'CLERK' JOB,1300 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'ACCOUNTING' DNAME,'MANAGER' JOB,2450 SAL FROM DUAL
UNION ALL
SELECT '2' CLASS, 'ACCOUNTING' DNAME,'PRESIDENT' JOB,5000 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'RESEARCH' DNAME,'ANALYST' JOB,6000 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'RESEARCH' DNAME,'CLERK' JOB,1900 SAL FROM DUAL
UNION ALL
SELECT '1' CLASS, 'RESEARCH' DNAME,'MANAGER' JOB,2975 SAL FROM DUAL
UNION ALL
SELECT '2' CLASS, 'SALES' DNAME,'MANAGER' JOB,28500 SAL FROM DUAL
UNION ALL
SELECT '2' CLASS, 'SALES' DNAME,'SALESMAN' JOB,4000 SAL FROM DUAL
)
SELECT CLASS, DNAME,JOB,SUM(SAL)
FROM TEST
GROUP BY CLASS,CUBE(DNAME,JOB)
HAVING GROUPING(DNAME)||GROUPING(JOB)<>'11'
ORDER BY GROUPING(DNAME)||GROUPING(JOB).
결과
----------------------------------------------------
CL DNAME JOB SUM(SAL)
-- -------------------- ------------------ ----------
1 RESEARCH CLERK 1900
1 RESEARCH ANALYST 6000
1 RESEARCH MANAGER 2975
1 ACCOUNTING MANAGER 2450
2 SALES SALESMAN 4000
2 ACCOUNTING PRESIDENT 5000
2 SALES MANAGER 28500
1 ACCOUNTING CLERK 1300
1 RESEARCH 10875
1 ACCOUNTING 3750
2 ACCOUNTING 5000
2 SALES 32500
1 CLERK 3200
1 ANALYST 6000
2 SALESMAN 4000
2 PRESIDENT 5000
2 MANAGER 28500
1 MANAGER 5425
요런 결과가 나오네요..^^: 설명은 강좌 란에...