
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
강의 자료에 써있는 해설과 강사님이 설명하시는 해설이 달라요!
작성한 코드 및 에러 메세지
select c1.title, c2.week, count(*) as cnt from courses c1
inner join checkins c2 on c1.course_id = c2.course_id
inner join orders o on c2.user_id = o.user_id
where o.created_at >= '2020-08-01'
group by c1.title, c2.week
order by c1.title, c2.week
22쪽 강의 자료에는 위의 쿼리를 이용한다고 나와있고 강사님도 저기에 select '~월' as month 추가하시고
union all을 하셨는데
(
select '7월' as month, c.title, c2.week, count(*) as cnt from checkins c2
inner join courses c on c2.course_id = c.course_id
inner join orders o on o.user_id = c2.user_id
where o.created_at < '2020-08-01'
group by c2.course_id, c2.week
order by c2.course_id, c2.week
)
union all
(
select '8월' as month, c.title, c2.week, count(*) as cnt from checkins c2
inner join courses c on c2.course_id = c.course_id
inner join orders o on o.user_id = c2.user_id
where o.created_at > '2020-08-01'
group by c2.course_id, c2.week
order by c2.course_id, c2.week
)
23쪽에는 위의 자료로 해설이 되어 있어요.
또 group by는 c2.course_id, c2.week 로 묶여져 있는데
select '8월' as month, c.title, c2.week, count(*) 로 되어져있는 이유도 궁금합니다.
select '8월' as month, c2.course_id, c2.week , count(*) 가 아닌가요?
유용한 강의 감사합니다!
