--향상된 group 함수-------------------------------------------------------------
--일반 group by
select department_id, job_id, sum(salary)
from employees
where department_id < 60
group by (department_id, job_id)
order by department_id;
--rollup group by
select department_id, job_id, sum(salary)
from employees
where department_id < 60
group by rollup(department_id, job_id);
--cube group by
select department_id, job_id, sum(salary)
from employees
where department_id < 60
group by cube(department_id, job_id);
--grouping (1: group by를 하지 않음 // 0: group by 적용됨)
select department_id, job_id, sum(salary), grouping(department_id) grp_derpt, grouping(job_id) grp_job
from employees
where department_id < 60
group by cube(department_id, job_id);
--grouping sets
select department_id, job_id, manager_id, avg(salary),
grouping(department_id) grp_derpt, grouping(job_id) grp_job, grouping(manager_id) grp_man
from employees
group by grouping sets
((department_id, job_id), (job_id, manager_id));
'ORACLE > SQL' 카테고리의 다른 글
다중 테이블 insert (0) | 2013.02.21 |
---|---|
계층검색(트리검색) (0) | 2013.02.20 |
set연산자 (union, intersect, minus) (0) | 2013.02.20 |
제약조건(constraint) 생성, 수정, 삭제 실습 (cascade) (0) | 2013.02.20 |
테이블 생성, 수정 실습 (0) | 2013.02.20 |