커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
5주차 실습과제
엑셀보다 쉽고 빠른 SQL
챕터 5
북마크
김*현
댓글
1
추천
0
조회수
12
조회수
12
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


피봇 테이블에서 sum이 아니라 max를 써야 하는 이유가 무엇인가요?

<<sum>>(if(age=10,주문건수, 0)) "10대",



select

cuisine_type,

sum(if(age=10,주문건수, 0)) "10대",

sum(if(age=20,주문건수, 0)) "20대",

sum(if(age=30,주문건수, 0)) "30대",

sum(if(age=40,주문건수, 0)) "40대",

sum(if(age=50,주문건수, 0)) "50대"

from

(

select

f.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,

count(1) 주문건수

from food_orders f inner join customers c on f.customer_id=c.customer_id

where age between 10 and 59

group by 1, 2

) a

group by 1









취소
 공유
취소
댓글 0
댓글 알림
나의얼굴