Roel Notebook

[SQL] 식품분류별 가장 비싼 식품의 정보 조회하기

by Roel Downey
728x90
반응형

[SQL] 식품분류별 가장 비싼 식품의 정보 조회하기

 

 

문제 

- 문제 링크: 프로그래머스

 

 

 

풀이

 

SELECT category, price AS max_price, product_name
FROM food_product
WHERE (category,price) IN (
    SELECT category, MAX(price) AS max_price
    FROM food_product
    WHERE category IN ('과자', '국', '김치', '식용유')
    GROUP BY category
)
ORDER BY price DESC

 

SELECT CATEGORY, PRICE AS MAX_PRICE, PRODUCT_NAME
FROM FOOD_PRODUCT
WHERE CATEGORY IN ('과자', '국', '김치', '식용유')
AND PRICE IN (SELECT MAX(PRICE) FROM FOOD_PRODUCT GROUP BY CATEGORY)
GROUP BY CATEGORY
ORDER BY MAX_PRICE DESC

 

 

728x90
반응형

블로그의 정보

What doing?

Roel Downey

활동하기