음식 타입별, 연령별 주문건수 pivot view 만들기
더보기
![](https://blog.kakaocdn.net/dn/bEEYbN/btsLtIs78QD/msedeqY2NK8wqO2dZNDcP0/img.png)
select cuisine_type,
max(if(age_group=10,order_count,0)) '10대',
max(if(age_group=20,order_count,0)) '20대',
max(if(age_group=30,order_count,0)) '30대',
max(if(age_group=40,order_count,0)) '40대',
max(if(age_group=50,order_count,0)) '50대'
from
(
select fo.cuisine_type,
case when age between 10 and 19 then 10
when age between 20 and 29 then 20
when age between 30 and 39 then 30
when age between 40 and 49 then 40
when age between 50 and 59 then 50
end age_group,
count(1) order_count
from food_orders fo inner join customers c on fo.customer_id = c.customer_id
where c.age between 10 and 59
group by 1, 2
) a
group by 1
#
![](https://blog.kakaocdn.net/dn/bEEYbN/btsLtIs78QD/msedeqY2NK8wqO2dZNDcP0/img.png)
'내일배움캠프 강의 숙제' 카테고리의 다른 글
[2025/01/02]데이터 전처리 & 시각화 숙제 (0) | 2025.01.02 |
---|---|
[2024/12/20]엑셀보다 쉽고 빠른 SQL 4주차 숙제 (0) | 2024.12.20 |
[2024/12/20]엑셀보다 쉽고 빠른 SQL 3주차 숙제 (0) | 2024.12.20 |
[2024/12/19]엑셀보다 쉽고 빠른 SQL 2주차 숙제 (0) | 2024.12.19 |
[2024/12/19]데이터 분석 종합반 5주차 숙제 (0) | 2024.12.19 |