PROGRAMMERS

[SQL 고득점 Kit][JOIN][Level 5] 상품을 구매한 회원 비율 구하기

콘순이 2025. 2. 9. 19:39

https://school.programmers.co.kr/learn/courses/30/lessons/131534

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

select year(sales_date) as year, month(sales_date) as month, 
count(distinct o.user_id) as purchased_users, 
round(count(distinct o.user_id) / c.count, 1) as purchased_ratio
from ONLINE_SALE o join user_info u 
on o.user_id = u.user_id 
join (select count(u.user_id) as count from user_info u where year(u.joined) = 2021) c
where year(u.joined) = 2021
group by year, month
order by year, month