즐겨찾기가 가장 많은 식당 정보 출력하기
REST_INFO 테이블에서 음식종류별로 즐겨찾기수가 가장 많은 식당의 음식 종류, ID, 식당 이름, 즐겨찾기수를 조회하는 SQL문을 작성해주세요. 이때 결과는 음식 종류를 기준으로 내림차순 정렬해주세요.
지금와서 생각해보니 즐겨찾기수를 조작하는거면 having이 아니라 where을 썻어야 했네... 이걸 지금 블로깅 하면서 생각했네😳
SELECT food_type, rest_id, rest_name, max(favorites)
from rest_info
#where
group by food_type
having max(favorites) limit 1 # max와 limit은 같은 말인데
order by food_type desc
# having
SELECT food_type,rest_id,rest_name,favorites
from rest_info
group by food_type
having (max(favorites))
order by food_type desc
#where #서브쿼리
SELECT food_type,rest_id,rest_name,favorites from rest_info
where favorites in (select max(favorites) from rest_info
group by food_type)
group by food_type
order by food_type desc