bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1341. Movie Rating

1341. Movie Rating

Leetcode Solutions

Group By and Order By with Limit

  1. Join the MovieRating and Users tables on user_id and group the result by user_id.
  2. Count the number of ratings for each user and order the result by the count in descending order and by user name in ascending order.
  3. Select the top result using LIMIT 1 to get the user with the most ratings.
  4. Join the MovieRating and Movies tables on movie_id and filter the ratings to only include those from February 2020.
  5. Group the result by movie_id and calculate the average rating for each movie.
  6. Order the result by the average rating in descending order and by movie title in ascending order.
  7. Select the top result using LIMIT 1 to get the movie with the highest average rating.
  8. Combine the two results using UNION ALL.

erDiagram
    Movies {
        int movie_id PK
        varchar title
    }
    Users {
        int user_id PK
        varchar name
    }
    MovieRating {
        int movie_id PK
        int user_id PK
        int rating
        date created_at
    }

Using Window Functions for Ranking

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...