Skip to content

Commit 18559ef

Browse files
committed
Create 1341. Movie Rating.sql
1 parent 97ad079 commit 18559ef

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
1341. Movie Rating
2+
Solved
3+
Medium
4+
Topics
5+
Companies
6+
SQL Schema
7+
Pandas Schema
8+
Table: Movies
9+
10+
+---------------+---------+
11+
| Column Name | Type |
12+
+---------------+---------+
13+
| movie_id | int |
14+
| title | varchar |
15+
+---------------+---------+
16+
movie_id is the primary key (column with unique values) for this table.
17+
title is the name of the movie.
18+
19+
20+
Table: Users
21+
22+
+---------------+---------+
23+
| Column Name | Type |
24+
+---------------+---------+
25+
| user_id | int |
26+
| name | varchar |
27+
+---------------+---------+
28+
user_id is the primary key (column with unique values) for this table.
29+
The column 'name' has unique values.
30+
Table: MovieRating
31+
32+
+---------------+---------+
33+
| Column Name | Type |
34+
+---------------+---------+
35+
| movie_id | int |
36+
| user_id | int |
37+
| rating | int |
38+
| created_at | date |
39+
+---------------+---------+
40+
(movie_id, user_id) is the primary key (column with unique values) for this table.
41+
This table contains the rating of a movie by a user in their review.
42+
created_at is the user's review date.
43+
44+
45+
Write a solution to:
46+
47+
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.
48+
Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.
49+
The result format is in the following example.
50+
51+
52+
53+
Example 1:
54+
55+
Input:
56+
Movies table:
57+
+-------------+--------------+
58+
| movie_id | title |
59+
+-------------+--------------+
60+
| 1 | Avengers |
61+
| 2 | Frozen 2 |
62+
| 3 | Joker |
63+
+-------------+--------------+
64+
Users table:
65+
+-------------+--------------+
66+
| user_id | name |
67+
+-------------+--------------+
68+
| 1 | Daniel |
69+
| 2 | Monica |
70+
| 3 | Maria |
71+
| 4 | James |
72+
+-------------+--------------+
73+
MovieRating table:
74+
+-------------+--------------+--------------+-------------+
75+
| movie_id | user_id | rating | created_at |
76+
+-------------+--------------+--------------+-------------+
77+
| 1 | 1 | 3 | 2020-01-12 |
78+
| 1 | 2 | 4 | 2020-02-11 |
79+
| 1 | 3 | 2 | 2020-02-12 |
80+
| 1 | 4 | 1 | 2020-01-01 |
81+
| 2 | 1 | 5 | 2020-02-17 |
82+
| 2 | 2 | 2 | 2020-02-01 |
83+
| 2 | 3 | 2 | 2020-03-01 |
84+
| 3 | 1 | 3 | 2020-02-22 |
85+
| 3 | 2 | 4 | 2020-02-25 |
86+
+-------------+--------------+--------------+-------------+
87+
Output:
88+
+--------------+
89+
| results |
90+
+--------------+
91+
| Daniel |
92+
| Frozen 2 |
93+
+--------------+
94+
Explanation:
95+
Daniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.
96+
Frozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.
97+
98+

0 commit comments

Comments
 (0)