Porgrammers/프로그래머스-가격대 별 상품 개수 구하기-MySQL

cosmos·2022년 11월 1일
0
post-thumbnail
post-custom-banner

문제

쿼리

SELECT CASE WHEN PRICE > 0 AND PRICE < 10000 THEN 0
            WHEN PRICE >= 10000 AND PRICE < 20000 THEN 10000
            WHEN PRICE >= 20000 AND PRICE < 30000 THEN 20000
            WHEN PRICE >= 30000 AND PRICE < 40000 THEN 30000
            WHEN PRICE >= 40000 AND PRICE < 50000 THEN 40000
            WHEN PRICE >= 50000 AND PRICE < 60000 THEN 50000
            WHEN PRICE >= 60000 AND PRICE < 70000 THEN 60000
            WHEN PRICE >= 70000 AND PRICE < 80000 THEN 70000
            WHEN PRICE >= 80000 AND PRICE < 90000 THEN 80000
            WHEN PRICE >= 90000 AND PRICE < 100000 THEN 90000
            END AS PRICE_GROUP,
            COUNT(*) AS PRODUCTS
FROM PRODUCT
GROUP BY PRICE_GROUP
ORDER BY PRICE_GROUP

결과

출처 & 깃허브

프로그래머스
github

post-custom-banner

0개의 댓글