본문 바로가기

Coding Test/프로그래머스

[프로그래머스/MySQL] 식품분류별 가장 비싼 식품의 정보 조회하기

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