<aside> 🧙♂️ GROUP BY 항목들간 다차원적인 소계를 계산할 수 있는 CUBE 함수
</aside>
CUBE는 결합 가능한 모든 값에 대해 집계를 생성한다.
시스템에 부담이 많이 간다.
select case
grouping(t.orig_yyyy)
when 1 then 'ALL Orig_yyyy'
else t.orig_yyyy
end "Orig_yyyy",
case
grouping(t.team_name)
when 1 then 'ALL Team'
else t.team_name
end "Team",
count(*) 선수수,
round(avg(p.height), 1) 평균키
from team t
join player p on t.team_id = p.team_id
group by CUBE(t.orig_yyyy, t.team_name);
ROLLUP일 경우에는
t.orig_yyyy, t.team_name 을 group 으로
t.orig_yyyy 을 group으로 반복 후에
() 이지만
CUBE일 경우에는
t.team_name을 group으로
t.orig_yyyy을 group으로 전체 반복한다.