스파르타/SQL

SQL_3주차_ join 퀴즈

옒르 2023. 1. 12. 18:18

✅ 결제 수단 별 유저 포인트의 평균값 구해보기 _ round 사용해서 반올림하기

select o.payment_method ,ROUND(AVG(p.point)) as avg_point from point_users p

inner join orders o on p.user_id = o.user_id

group by o.payment_method

 

✅ 결제하고 시작하지 않은 유저들을 성씨별로 세어보기

select u.name , COUNT(*) as cnt_name from enrolleds e

inner join users u on u.user_id = e.user_id

where e.is_registered = 0

group by u.name

order by cnt_name desc

 

✅ 과목 별로 시작하지 않은 유저들을 세어보기

select c.course_id, c.title , COUNT(*) as cnt_notstart from courses c

inner join enrolleds e on c.course_id = e.course_id

where e.is_registered =0

group by c.course_id

 

 웹개발, 앱개발 종합반의 week 별 체크인 수를 세어볼까요? 보기 좋게 정리해보기

select c.title ,ch.week ,COUNT(*) as cnt from courses c

inner join checkins ch on c.course_id = ch.course_id

group by c.title , ch.week

order by c.title ,ch.week

 

 연습4번에서, 8월 1일 이후에 구매한 고객들만 발라내어 보기

select c.title ,ch.week ,COUNT(*) as cnt from courses c

inner join checkins ch on c.course_id = ch.course_id         # join에 또 join을 할 수 있음

inner join orders o on ch.user_id = o.user_id

where o.created_at >= '2020-08-01'

group by c.title ,ch.week

order by c.title ,ch.week

'스파르타 > SQL' 카테고리의 다른 글

SQL_3주차_ Union  (0) 2023.01.12
SQL_3주차_ Left join  (0) 2023.01.12
SQL_3주차_ join 기초  (0) 2023.01.12
SQL_2주차_숙제  (0) 2023.01.04
SQL_2주차_Group by와 Order by  (0) 2023.01.03