select e.enrolled_id, e.user_id, count(*) as cnt from enrolleds_detail ed
inner join enrolleds e on ed.enrolled_id = e.enrolled_id
where ed.done = 1
group by e.enrolled_id
order by cnt DESC
(
select '7월' as month, 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
)
union all
(
select '8월' as month, 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
)
3주차에 접어들자 조금씩 머리를 써야하는 코딩을 배우게 되었다. 실질적으로 배운 것은 join 하나이지만, 이전에 배웠던 것들을 종합하여 원하는 결과를 도출해 봄으로써 기존에 배웠던 부분을 어떠한 방식으로 활용하여 데이터를 추출해야하는지 배울 수 있었다.
SQL 데이터베이스에 접근하여 inner join, left join 기능을 사용하였으며, 이전에 배운 where, like, group by, order by 등과 혼합하여 원하는 데이터를 가져오는 방법을 배웠다.