글
프로그래머스 레벨5 상품을 구매한 회원 비율 구하기
select YEAR, MONTH, PUCHASED_USERS, round(PUCHASED_USERS/tot_cnt,1) PUCHASED_RATIO
from (select year, to_number(month) month, count(1) PUCHASED_USERS
from (select distinct to_char(b.sales_date, 'yyyy') year, to_char(b.sales_date, 'mm') month, user_id
from online_sale b
where exists (select 'x'
from user_info q
where to_char(q.joined, 'yyyy') = '2021' and q.user_id = b.user_id)) a1
group by year, month) a2, (select count(1) tot_cnt from user_info where to_char(joined, 'yyyy') = '2021') b2
order by year, month;
////
select
to_char(b.sales_date, 'YYYY') as year
, to_number(to_char(b.sales_date, 'MM')) as month
, count(distinct(b.user_id)) as PUCHASED_USERS
, round(count(distinct(b.user_id))/
(select count(*) from user_info a where to_char(a.joined, 'YYYY') = '2021'), 1) as PUCHASED_RATIO
from user_info a, online_sale b
where a.user_id = b.user_id
and to_char(a.joined, 'YYYY') = '2021'
group by to_char(b.sales_date, 'YYYY'), to_number(to_char(b.sales_date, 'MM'))
order by 1, 2
'SQL프로그래밍' 카테고리의 다른 글
프로그래머스 레벨3 오프라인/온라인 판매 데이터 통합하기 (0) | 2025.05.24 |
---|---|
프로그래머스 레벨2 상품별 오프라인 매출 구하기 (0) | 2025.05.24 |
프로그래머스 레벨4 년, 월, 성별 별 상품 구매 회원 수 구하기 (0) | 2025.05.24 |
프로그래머스 레벨4 그룹별 조건에 맞는 식당 목록 출력하기 (0) | 2025.05.24 |
프로그래머스 레벨4 주문량이 많은 아이스크림들 조회하기 (0) | 2025.05.22 |