We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f1cf6d commit 2f7f01bCopy full SHA for 2f7f01b
MySQL/movie-rating.sql
@@ -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
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