Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sql] 서울에 위치한 식당 목록 출력하기 #217

Closed
hwangJi-dev opened this issue Apr 27, 2023 · 0 comments
Closed

[Sql] 서울에 위치한 식당 목록 출력하기 #217

hwangJi-dev opened this issue Apr 27, 2023 · 0 comments

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Apr 27, 2023

💬 문제

https://school.programmers.co.kr/learn/courses/30/lessons/13111


💬 Idea

  • REST_ID를 기준으로 JOIN을 해준다.
  • ADDRESS가 서울로 시작하는 것으로 필터링한다.
  • 리뷰값의 평균값을 구하기 위해 REST_ID로 그룹핑한다.
  • 결과는 평균점수를 기준으로 내림차순 정렬하고, 평균점수가 같다면 즐겨찾기수를 기준으로 내림차순 정렬한다.

💬 풀이

SELECT ri.REST_ID, ri.REST_NAME, ri.FOOD_TYPE, ri.FAVORITES, ri.ADDRESS, ROUND(AVG(rr.REVIEW_SCORE), 2) AS SCORE
FROM REST_INFO AS ri INNER JOIN REST_REVIEW AS rr
ON ri.REST_ID = rr.REST_ID
WHERE ri.ADDRESS LIKE "서울%"
GROUP BY ri.REST_ID
ORDER BY SCORE DESC, ri.FAVORITES DESC

💬 알게된 문법

✅ ORDER BY 우선순위 부여

  • 정렬 우선순위가 높은 것부터 기재해준다.

✅ 평균값 구하기 (AVG)

  • AVG(컬럼명)

✅ 반올림 하기 (ROUND)

  • ROUND(값, 자릿수)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant