1341. Movie Rating
https://leetcode.com/problems/movie-rating/
Movie Rating - LeetCode
Can you solve this real interview question? Movie Rating - Table: Movies +---------------+---------+ | Column Name | Type | +---------------+---------+ | movie_id | int | | title | varchar | +---------------+---------+ movie_id is the primary key for this
leetcode.com
Write an SQL query to:
- Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.
- Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.
# 가장 많은 수의 영화를 평가한 사용자의 이름을 찾으십시오. 동점인 경우 사전순으로 더 작은 사용자 이름을 반환합니다.
# 2020년 2월 평균 평점이 가장 높은 영화 이름을 찾습니다. 동률인 경우 사전순으로 더 작은 영화 이름을 반환합니다.
답
(
SELECT U.name AS results
FROM MovieRating R LEFT JOIN Users U USING(user_id)
GROUP BY R.user_id
ORDER BY COUNT(R.movie_id) DESC, U.name -- 평가한 영화 많은 순, 이름순으로
LIMIT 1
)
UNION ALL
(
SELECT M.title AS results
FROM MovieRating R LEFT JOIN Movies M USING(movie_id)
WHERE R.created_at LIKE '2020-02%'
GROUP BY R.movie_id
ORDER BY AVG(R.rating) DESC, M.title -- 평점 높은 순, 이름순으로
LIMIT 1
)
'🛠️Skill > CodingTest' 카테고리의 다른 글
[leetcode] 262. Trips and Users / 취소 비율 구하기 (0) | 2023.04.17 |
---|---|
[leetcode] 1321. Restaurant Growth/7일간의 이동 평균 (0) | 2023.03.29 |
[leetcode] 1204. Last Person to Fit in the Bus / 버스 마지막 승객 구하기 (0) | 2023.03.09 |
[leetcode] 1174. Immediate Food Delivery II / 즉시배송할 수 있는 주문비율 (0) | 2023.03.08 |
[leetcode] 550. Game Play Analysis IV/ 이틀 연속 로그인한 유저 /LEFT JOIN/IN (0) | 2023.02.19 |
댓글