Cube and Rollup Example
Cube and Rollup Example
Cube and Rollup Example
count(*),
SQL> SELECT DEPTNO, JOB, COUNT(*) FROMEMP GROUP BY CUBE(DEPTNO,JOB); DEPTNO JOB COUNT(*) --------------------------10 CLERK 1 10 MANAGER 1 10 PRESIDENT 1 10 3 20 ANALYST 2 20 CLERK 2 20 MANAGER 1
Create cross-tabular reports with CUBE In multidimensional jargon, a cube is a cross-tabulated summary of detail rows. CUBE enables a SELECT statement to calculate subtotals for all possible combinations of a group of dimensions. It also calculates a grand total. This is the set of information typically needed for all cross-tabular reports, so CUBE can calculate a cross-tabular report with a single select statement. Note in the example below that totals are calculated for each department, and also for each job category. SELECT deptno, job, count(*), sum(sal) FROM emp GROUP BY CUBE(deptno,job); DEPTNO --------10 10 10 10 20 20 20 20 30 30 30 30 JOB COUNT(*) --------- --------CLERK 1 MANAGER 1 PRESIDENT 1 3 ANALYST 2 CLERK 2 MANAGER 1 5 CLERK 1 MANAGER 1 SALESMAN 4 6 ANALYST 2 CLERK 4 MANAGER 3 PRESIDENT 1 SUM(SAL) --------1300 2450 5000 8750 6000 1900 2975 10875 950 2850 5600 9400 6000 4150 8275 5000
SALESMAN
4 14
5600 29025