SQL 문제풀이
[프로그래머스 SQL] LV.4 서울에 위치한 식당 목록 출력하기
냄비짱
2023. 8. 6. 00:21
728x90
❓ Question
❗ Answer
SELECT info.rest_id, info.rest_name, info.food_type, info.favorites, info.address,
ROUND(AVG(review.review_score),2) score
FROM rest_info info
INNER JOIN rest_review review
ON info.rest_id = review.rest_id
WHERE info.address LIKE '서울%'
GROUP BY rest_id
ORDER BY score DESC, info.favorites DESC;
📌 Discussion
- WHERE 문에서 join을 시키고 조건을 달아준 뒤
- 집계를 위해서 group by를 해주고, ROUND로 반올림해줌
- null이 있는 레코드의 avg를 구하면 값이 나오지 않음(연산 진행 불가)