일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- tableau
- mysql
- Level2
- counter
- lambda
- itertools
- 프로그래머스
- 파이썬
- hackerrank
- Growth hacking
- time complexity
- Stack
- cte
- lv4
- 조합
- LeetCode
- import re
- level4
- python
- AARRR
- 완전탐색
- 코딩
- join
- sql
- Queue
- coding
- coding test
- programmers
- 코테
- 코딩테스트
Archives
- Today
- Total
ror_coding
[LeetCode] 1341. Movie Rating 본문
728x90
문제를 잘 읽자!!! subquery를 잘 활용하자..!
Question
Write a solution 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.
The result format is in the following example.
Code
select name as results
from users
where user_id = (
select user_id
from movierating
join users using(user_id)
group by 1
order by count(*) desc, name
limit 1
)
union all
select title as results
from movies
where movie_id = (
select movie_id
from movierating
join movies using(movie_id)
where created_at like '2020-02%'
group by 1
order by avg(rating) desc, title
limit 1
)
My Code
728x90
'Coding Test > SQL' 카테고리의 다른 글
[LeetCode] 1321. Restaurant Growth (0) | 2025.07.19 |
---|---|
[LeetCode] 626. Exchange Seats (0) | 2025.07.19 |
[LeetCode] 1907. Count Salary Categories (1) | 2025.07.19 |
[LeetCode] 1934. Confirmation Rate (0) | 2025.07.13 |
[LeetCode] 176. Second Highest Salary (0) | 2025.07.13 |