Skip to content

Commit 2f7f01b

Browse files
authored
Create movie-rating.sql
1 parent 5f1cf6d commit 2f7f01b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

MySQL/movie-rating.sql

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Time: O(nlogn), n is the number of movie_rating
2+
# Space: O(n)
3+
4+
(SELECT b.name AS results
5+
FROM (SELECT a.user_id,
6+
Count(*) AS cnt
7+
FROM movie_rating a
8+
GROUP BY a.user_id) a
9+
INNER JOIN users b
10+
ON a.user_id = b.user_id
11+
ORDER BY a.cnt DESC,
12+
b.name ASC
13+
LIMIT 1)
14+
UNION ALL
15+
(SELECT b.movie_name
16+
FROM (SELECT a.movie_name,
17+
Avg(a.rating) AS max_rating
18+
FROM (SELECT a.rating,
19+
b.title AS movie_name
20+
FROM movie_rating a
21+
INNER JOIN movies b
22+
ON a.movie_id = b.movie_id
23+
WHERE a.created_at BETWEEN '2020-02-01' AND '2020-02-29') a
24+
GROUP BY a.movie_name) b
25+
ORDER BY b.max_rating DESC,
26+
b.movie_name ASC
27+
LIMIT 1);
28+

0 commit comments

Comments
 (0)