
[정답 쿼리]
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
[정답 쿼리]를 보면 join 문법으로 우선 courses와 checkins 테이블을 묶은 뒤
checkins에 orders 테이블을 한번 더 묶는데요.
이 때,
1) courses와 checkins 테이블은 course.id로 묶고
2) checkins과 orders 테이블은 user.id로 묶고 있습니다.
제가 궁금한 점은,
세 테이블 모두 course id 를 공통으로 갖고 있는데
두번째로 checkins과 orders 테이블을 묶을 때는 course.id 가 아닌 user.id로 묶는 이유는
user.id가 더 분별 있는(?) 기준이기 때문인가요?
