Skip to content

Commit 6c62c66

Browse files
committed
Upload 132
1 parent 00e0466 commit 6c62c66

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ The problems and both submitted and site solutions are documented in individual
164164
| 129 | [Count Salary Categories](https://leetcode.com/problems/count-salary-categories/description/) | [Solution](solutions/129_count_salary_categories.md) | LeetCode | Medium | `IFNULL` |
165165
| 130 | [Employees Whose Manager Left the Company](https://leetcode.com/problems/employees-whose-manager-left-the-company/description/) | [Solution](solutions/130_employees_whose_manager_left_the_company.md) | LeetCode | Easy | |
166166
| 131 | [Exchange Seats](https://leetcode.com/problems/exchange-seats/description/) | [Solution](solutions/131_exchange_seats.md) | LeetCode | Medium | `CASE` w/ `LAG` w/ `COALESCE` |
167+
| 132 | [Movie Rating](https://leetcode.com/problems/movie-rating/description/) | [Solution](solutions/132_movie_rating.md) | LeetCode | Medium | |
167168
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
168169

169170
## Author(s)

solutions/132_movie_rating.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SQL Everyday \#132
2+
3+
## Movie Rating
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
Write a solution to:
11+
12+
* 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.
13+
* Find the movie name with the *highest average* rating in `February 2020`. In case of a tie, return the lexicographically smaller movie name. [[Full Description](https://leetcode.com/problems/movie-rating/description/)]
14+
15+
## Submitted Solution
16+
17+
```sql
18+
-- Submitted Solution
19+
WITH cte1 AS (
20+
SELECT
21+
mr.user_id
22+
,u.name
23+
,COUNT(mr.rating) AS count_ratings
24+
FROM MovieRating AS mr
25+
JOIN Users u ON mr.user_id = u.user_id
26+
GROUP BY mr.user_id
27+
ORDER BY count_ratings DESC, u.name ASC
28+
LIMIT 1
29+
),
30+
cte2 AS (
31+
SELECT
32+
mr.movie_id
33+
,mv.title
34+
,AVG(mr.rating) AS avg_rating
35+
,mr.created_at
36+
FROM MovieRating AS mr
37+
JOIN Movies mv ON mr.movie_id = mv.movie_id
38+
WHERE EXTRACT(YEAR FROM mr.created_at) = 2020 AND EXTRACT(MONTH FROM mr.created_at) = 2
39+
GROUP BY mr.movie_id
40+
ORDER BY avg_rating DESC, mv.title ASC
41+
LIMIT 1
42+
)
43+
SELECT
44+
name AS results
45+
FROM cte1
46+
UNION ALL
47+
SELECT
48+
title AS results
49+
FROM cte2
50+
;
51+
```
52+
53+
## Site Solution
54+
55+
```sql
56+
-- LeetCode Solution
57+
-- None
58+
```
59+
60+
## Notes
61+
62+
TBD
63+
64+
## NB
65+
66+
TBD
67+
68+
Go to [Index](../?tab=readme-ov-file#index)\
69+
Go to [Overview](../?tab=readme-ov-file)
70+

0 commit comments

Comments
 (0)