본문 바로가기

공부/SQL

[SQL/오라클] ROLLUP, CUBE, GROUPING SETS

데이터를 ROLLUP, CUBE, GROUPING SET으로 출력

 

select * from sqld_34_20; 

 

 

  • ROLLUP
  select id, dept_nm, sum(salary)
    from sqld_34_20
group by rollup(id, dept_nm);

 

  • CUBE
  select id, dept_nm, sum(salary)
    from sqld_34_20
group by cube(id, dept_nm);

 

 

  • GROUPING SETS
  select id, dept_nm, sum(salary)
    from sqld_34_20
group by grouping sets(id, dept_nm);

 

 


  select id, dept_nm, sum(salary)
    from sqld_34_20
group by grouping sets((id, dept_nm));

 

  select id, dept_nm, sum(salary)
    from sqld_34_20
group by grouping sets(id, dept_nm, ());

'공부 > SQL' 카테고리의 다른 글

[SQL/오라클]NVL, NULLIF, COALESCE  (0) 2020.11.27
[SQL/오라클]UPPER, LOWER, INITCAP  (0) 2020.11.27
[SQL/오라클] DROP vs DELETE vs TRUNCATE 차이  (0) 2020.11.18
[SQL/오라클] NULL 개념  (0) 2020.11.18
SQL Injection(삽입) 공격  (0) 2020.09.14