https://school.programmers.co.kr/learn/courses/30/lessons/131116
group by를 사용할 때 집계함수를 사용한 컬럼이 있을 경우 실행이 되지 않든가, 정확하지 않은 값이 나올 수 있다.
따라서 서브 쿼리로 따로 빼줘야 한다.
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
'코딩테스트 > MySQL' 카테고리의 다른 글
[프로그래머스 Level 4] 취소되지 않은 진료 예약 조회하기 (MySQL) (0) | 2024.12.08 |
---|---|
[프로그래머스 Level 4] 5월 식품들의 총매출 조회하기 (MySQL) (0) | 2024.12.02 |
[프로그래머스 Level 4] 보호소에서 중성화한 동물 (MySQL) (0) | 2024.11.25 |
[프로그래머스 Level 3] 대장균의 크기에 따라 분류하기 2 (MySQL) (feat. NTILE) (0) | 2024.11.24 |
[프로그래머스 Level 3] 물고기 종류 별 대어 찾기 (MySQL) (0) | 2024.11.23 |