Skip to content

Practice Movie Rating

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1341
LeetCode Problem

Movie Rating

Problem Statement

Tables: Movies(movie_id INT, title VARCHAR); Users(user_id INT, name VARCHAR); MovieRating(movie_id INT, user_id INT, rating INT, created_at DATE). Movies.movie_id and title are unique. Users.user_id and name are unique. MovieRating has key (movie_id, user_id); created_at is the rating date. Return two rows in the results column: first the user who rated the most movies overall, then the movie with the greatest average rating during February 2020. Break a user-count tie by lexicographically smallest user name and a rating-average tie by lexicographically smallest movie title. Preserve both rows even when the selected strings are identical.

Source: Movie Rating on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Movies table: +-------------+--------------+ | movie_id    |  title       | +-------------+--------------+ | 1           | Avengers     | | 2           | Frozen 2     | | 3           | Joker        | +-------------+--------------+ Users table: +-------------+--------------+ | user_id     |  name        | +-------------+--------------+ | 1           | Daniel       | | 2           | Monica       | | 3           | Maria        | | 4           | James        | +-------------+--------------+ MovieRating table: +-------------+--------------+--------------+-------------+ | movie_id    | user_id      | rating       | created_at  | +-------------+--------------+--------------+-------------+ | 1           | 1            | 3            | 2020-01-12  | | 1           | 2            | 4            | 2020-02-11  | | 1           | 3            | 2            | 2020-02-12  | | 1           | 4            | 1            | 2020-01-01  | | 2           | 1            | 5            | 2020-02-17  | | 2           | 2            | 2            | 2020-02-01  | | 2           | 3            | 2            | 2020-03-01  | | 3           | 1            | 3            | 2020-02-22  | | 3           | 2            | 4            | 2020-02-25  | +-------------+--------------+--------------+-------------+
Output
+--------------+ | results      | +--------------+ | Daniel       | | Frozen 2     | +--------------+

Related LeetCode Problems

Practice more problems similar to Movie Rating.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.