강의로 돌아가기
김지원

오라클 where절 max() 정답

-- 식품 분류별로 가격이 제일 비싼 식품(과자,국,김치,식용유만)
-- 식품의분류, 가격, 이름
-- 식품 가격 기준 내림차순 정렬
select category, price, productname
from food
product
where (category, price) in (select category, max(price) as maxprice
from food
product
where category in ('과자', '국', '김치', '식용유')
group by category)
order by price desc

작성중인 코드―solution.sql
1
2
3
4
5
6
7
8
9
10
-- 식품 분류별로 가격이 제일 비싼 식품(과자,국,김치,식용유만)
-- 식품의분류, 가격, 이름
-- 식품 가격 기준 내림차순 정렬
select category, 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
  • 최태승

    풀이에 어려움을 겪고 있었는데 감사합니다

    최태승―2022.12.31 16:32
0 개의 답변
답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다.