2021년에 가입한 전체 회원 수를 미리 구해놓고 문제에서 요구하는대로 년, 월별 구매한 유저 수를 구해 비율까지 구해주면 된다.
with t100 as
(select
count(user_id) as cntall
from user_info
where year(joined) = 2021)
select
year(sales_date) as year,
month(sales_date) as month,
count(distinct user_id) as puchased_users,
round(count(distinct user_id) / t100.cntall, 1) as puchased_ratio
from online_sale, t100
where user_id in (select
user_id
from user_info
where year(joined) = 2021)
group by 1, 2
order by 1, 2