[프로그래머스 SQL 고득점 Kit] GROUB BY: 가격대 별 상품 개수 구하기

jieunee·2023년 4월 1일
0

🤔 문제


✅ 정답

SELECT
    CASE
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 0 AND PRICE < 10000
        ) THEN 0
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 10000 AND PRICE < 20000
        ) THEN 10000
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 20000 AND PRICE < 30000
        ) THEN 20000
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 30000 AND PRICE < 40000
        ) THEN 30000
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 40000 AND PRICE < 50000
        ) THEN 40000
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 50000 AND PRICE < 60000
        ) THEN 50000
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 60000 AND PRICE < 70000
        ) THEN 60000
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 70000 AND PRICE < 80000
        ) THEN 70000
        WHEN PRICE IN
        (
            SELECT PRICE 
            FROM PRODUCT
            WHERE PRICE >= 80000 AND PRICE < 90000
        ) THEN 80000
    END AS PRICE_GROUP, COUNT(PRICE) AS PRODUCTS
FROM PRODUCT
GROUP BY PRICE_GROUP
ORDER BY PRICE_GROUP
profile
Back-End Developer 🌱

0개의 댓글