
5주차 4번째 pivot table 만들기에서,
pivot table view를 보여주기 위해 if 앞을 다시 MAX로 묶어줘야 한다고 설명 주셨는데,
설명에서는 복잡해서 이걸 따로 설명하진 않겠다라고 하셨어요. ㅠ
혹시 if 앞에 max로 묶어야 하는 이유가 뭘까요?
excel에서 pivot table을 만들때 필드 값 정렬 기준을 '평균' '합계' '최대값' '최소값' 등으로 정할 수 있는데, 그런것과 같은 맥락일까요?
(*근데 excel pivot에서 값 정렬 기준을 '최대값' '최소값'으로 했을 경우에는 그에 해당하는 값만 나와서 또 다른것 같기도 하고..)

select age,
max(if(gender='female',cnt_order,0)) female,
max(if(gender='male',cnt_order,0)) male
from
(
select c.age,
c.gender,
count(1) cnt_order
from customers c inner join food_orders fo on c.customer_id =fo.customer_id
where age between 10 and 59
group by 1,2
order by age desc
) a
group by 1
order by age
