GROUPING + ROLLUP
select t.orig_yyyy 창단년도,
grouping(t.orig_yyyy),
t.team_name 팀명,
grouping(t.team_name),
count(*) 선수수,
round(avg(p.height), 1) 평균키
from team t
join player p on t.team_id = p.team_id
group by rollup(t.orig_yyyy, t.team_name);
- GROUP BY로 묶이고 ROLLUP 되었을 때 2진수로 null을 나타내어준다.
GROUPING_ID
select t.orig_yyyy 창단년도,
grouping(t.orig_yyyy) as go,
t.team_name 팀명,
grouping(t.team_name) as gt,
grouping_id(t.orig_yyyy, t.team_name) as g_id,
count(*) 선수수,
round(avg(p.height), 1) 평균키
from team t
join player p on t.team_id = p.team_id
group by rollup(t.orig_yyyy, t.team_name);
- GROUPING으로 나온 2진수 값을 더해 10진수로 출력해준다.