<aside> 🧙‍♂️ 소그룹 간의 소계를 계산하는 ROLLUP 함수

</aside>

GROUP BY + ROLLUP()

select t.orig_yyyy 창단년도,
        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);
  1. t.orig_yyyy, t.team_name을 group 별로
  2. 후에 t.orig_yyyy만 group별로
  3. 1, 2 반복
  4. ()

GROUP BY + ROLLUP(())

select t.orig_yyyy 창단년도,
        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**))**;
  1. t.orig_yyyy, t.team_name 을 group 별로
  2. () 하나

원리

GROUP BY ROLLUP (A, B, C)

  1. A B C
  2. A B
  3. A