{ "data": { "question": { "questionId": "1480", "questionFrontendId": "1341", "boundTopicId": null, "title": "Movie Rating", "titleSlug": "movie-rating", "content": "
Table: Movies
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| movie_id | int |\n| title | varchar |\n+---------------+---------+\nmovie_id is the primary key (column with unique values) for this table.\ntitle is the name of the movie.\n\n\n
\n\n
Table: Users
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| user_id | int |\n| name | varchar |\n+---------------+---------+\nuser_id is the primary key (column with unique values) for this table.\n\n\n
\n\n
Table: MovieRating
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| movie_id | int |\n| user_id | int |\n| rating | int |\n| created_at | date |\n+---------------+---------+\n(movie_id, user_id) is the primary key (column with unique values) for this table.\nThis table contains the rating of a movie by a user in their review.\ncreated_at is the user's review date. \n\n\n
\n\n
Write a solution to:
\n\nFebruary 2020
. In case of a tie, return the lexicographically smaller movie name.The result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nMovies table:\n+-------------+--------------+\n| movie_id | title |\n+-------------+--------------+\n| 1 | Avengers |\n| 2 | Frozen 2 |\n| 3 | Joker |\n+-------------+--------------+\nUsers table:\n+-------------+--------------+\n| user_id | name |\n+-------------+--------------+\n| 1 | Daniel |\n| 2 | Monica |\n| 3 | Maria |\n| 4 | James |\n+-------------+--------------+\nMovieRating table:\n+-------------+--------------+--------------+-------------+\n| movie_id | user_id | rating | created_at |\n+-------------+--------------+--------------+-------------+\n| 1 | 1 | 3 | 2020-01-12 |\n| 1 | 2 | 4 | 2020-02-11 |\n| 1 | 3 | 2 | 2020-02-12 |\n| 1 | 4 | 1 | 2020-01-01 |\n| 2 | 1 | 5 | 2020-02-17 | \n| 2 | 2 | 2 | 2020-02-01 | \n| 2 | 3 | 2 | 2020-03-01 |\n| 3 | 1 | 3 | 2020-02-22 | \n| 3 | 2 | 4 | 2020-02-25 | \n+-------------+--------------+--------------+-------------+\nOutput: \n+--------------+\n| results |\n+--------------+\n| Daniel |\n| Frozen 2 |\n+--------------+\nExplanation: \nDaniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.\nFrozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 418, "dislikes": 148, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "{\"headers\": {\"Movies\": [\"movie_id\", \"title\"], \"Users\": [\"user_id\", \"name\"], \"MovieRating\": [\"movie_id\", \"user_id\", \"rating\", \"created_at\"]}, \"rows\": {\"Movies\": [[1, \"Avengers\"], [2, \"Frozen 2\"], [3, \"Joker\"]], \"Users\": [[1, \"Daniel\"], [2, \"Monica\"], [3, \"Maria\"], [4, \"James\"]], \"MovieRating\": [[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\"]]}}", "categoryTitle": "Database", "contributors": [], "topicTags": [ { "name": "Database", "slug": "database", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below\n", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef movie_rating(movies: pd.DataFrame, users: pd.DataFrame, movie_rating: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"56.5K\", \"totalSubmission\": \"139.1K\", \"totalAcceptedRaw\": 56523, \"totalSubmissionRaw\": 139116, \"acRate\": \"40.6%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\": {\"Movies\": [\"movie_id\", \"title\"], \"Users\": [\"user_id\", \"name\"], \"MovieRating\": [\"movie_id\", \"user_id\", \"rating\", \"created_at\"]}, \"rows\": {\"Movies\": [[1, \"Avengers\"], [2, \"Frozen 2\"], [3, \"Joker\"]], \"Users\": [[1, \"Daniel\"], [2, \"Monica\"], [3, \"Maria\"], [4, \"James\"]], \"MovieRating\": [[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\"]]}}", "metaData": "{\"mysql\": [\"Create table If Not Exists Movies (movie_id int, title varchar(30))\", \"Create table If Not Exists Users (user_id int, name varchar(30))\", \"Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)\"], \"mssql\": [\"Create table Movies (movie_id int, title varchar(30))\", \"Create table Users (user_id int, name varchar(30))\", \"Create table MovieRating (movie_id int, user_id int, rating int, created_at date)\"], \"oraclesql\": [\"Create table Movies (movie_id int, title varchar(30))\", \"Create table Users (user_id int, name varchar(30))\", \"Create table MovieRating (movie_id int, user_id int, rating int, created_at date)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"movie_rating\", \"pythondata\": [\"Movies = pd.DataFrame([], columns=['movie_id', 'title']).astype({'movie_id':'Int64', 'title':'object'})\", \"Users = pd.DataFrame([], columns=['user_id', 'name']).astype({'user_id':'Int64', 'name':'object'})\", \"MovieRating = pd.DataFrame([], columns=['movie_id', 'user_id', 'rating', 'created_at']).astype({'movie_id':'Int64', 'user_id':'Int64', 'rating':'Int64', 'created_at':'datetime64[ns]'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Movies (movie_id int, title varchar(30))\", \"Create table If Not Exists Users (user_id int, name varchar(30))\", \"Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)\"], \"database_schema\": {\"Movies\": {\"movie_id\": \"INT\", \"title\": \"VARCHAR(30)\"}, \"Users\": {\"user_id\": \"INT\", \"name\": \"VARCHAR(30)\"}, \"MovieRating\": {\"movie_id\": \"INT\", \"user_id\": \"INT\", \"rating\": \"INT\", \"created_at\": \"DATE\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Movies (movie_id int, title varchar(30))", "Create table If Not Exists Users (user_id int, name varchar(30))", "Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)", "Truncate table Movies", "insert into Movies (movie_id, title) values ('1', 'Avengers')", "insert into Movies (movie_id, title) values ('2', 'Frozen 2')", "insert into Movies (movie_id, title) values ('3', 'Joker')", "Truncate table Users", "insert into Users (user_id, name) values ('1', 'Daniel')", "insert into Users (user_id, name) values ('2', 'Monica')", "insert into Users (user_id, name) values ('3', 'Maria')", "insert into Users (user_id, name) values ('4', 'James')", "Truncate table MovieRating", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '1', '3', '2020-01-12')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '2', '4', '2020-02-11')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '3', '2', '2020-02-12')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '4', '1', '2020-01-01')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '1', '5', '2020-02-17')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '2', '2', '2020-02-01')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '3', '2', '2020-03-01')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('3', '1', '3', '2020-02-22')", "insert into MovieRating (movie_id, user_id, rating, created_at) values ('3', '2', '4', '2020-02-25')" ], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"
MySQL 8.0
.
mssql server 2019
.
Oracle Sql 11.2
.
Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0
\"], \"postgresql\": [\"PostgreSQL\", \"PostgreSQL 16
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }