와이유스토리

[SQL] 프로그래머스 상품을 구매한 회원 비율 구하기(*) 본문

코딩테스트/SQL

[SQL] 프로그래머스 상품을 구매한 회원 비율 구하기(*)

유(YOO) 2023. 2. 8. 23:44

 

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

SELECT
    YEAR(SALES_DATE) AS YEAR,
    MONTH(SALES_DATE) AS MONTH,
    COUNT(*) AS PUCHASED_USERS,
    ROUND(COUNT(*)/(SELECT COUNT(*) FROM USER_INFO WHERE JOINED LIKE "2021%"), 1) AS PUCHASED_RATIO
FROM USER_INFO
    INNER JOIN (SELECT * FROM ONLINE_SALE GROUP BY USER_ID, YEAR(SALES_DATE), MONTH(SALES_DATE)) ONLINE_SALE
    ON USER_INFO.USER_ID = ONLINE_SALE.USER_ID
WHERE JOINED LIKE "2021%"
GROUP BY YEAR, MONTH
ORDER BY YEAR, MONTH;
Comments