1) rollup
select deptno, job, sum(sal) as sum_sal
from emp
group by rollup(deptno, job)
order by 1, 2;
↓ ↓ ↓
select deptno, job, sum(sal) as sum_sal
from emp
group by grouping sets((deptno, job), (deptno), ())
order by 1, 2;
2) cube
select deptno, job, sum(sal) as sum_sal
from emp
group by cube(deptno, job)
order by 1, 2;
↓ ↓ ↓
select deptno, job, sum(sal) as sum_sal
from emp
group by grouping sets((deptno, job), (deptno), job, ())
order by 1, 2;
'Oracle > SQL Fundamentals II' 카테고리의 다른 글
14일차 # 4-17: Composite Columns (0) | 2012.04.23 |
---|---|
14일차 # 4-11: Grouping 함수 (0) | 2012.04.23 |
14일차 # 4-13 Grouping Sets (0) | 2012.04.23 |
14일차 # 4-9 Cube (0) | 2012.04.23 |
14일차 # 4-7 Rollup (0) | 2012.04.23 |