{ "data": { "question": { "questionId": "1480", "questionFrontendId": "1341", "categoryTitle": "Database", "boundTopicId": 90536, "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": "电影评分", "translatedContent": "
表:Movies
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| movie_id | int |\n| title | varchar |\n+---------------+---------+\nmovie_id 是这个表的主键(具有唯一值的列)。\ntitle 是电影的名字。\n\n\n
表:Users
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| user_id | int |\n| name | varchar |\n+---------------+---------+\nuser_id 是表的主键(具有唯一值的列)。\n\n\n
表: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) 是这个表的主键(具有唯一值的列的组合)。\n这个表包含用户在其评论中对电影的评分 rating 。\ncreated_at 是用户的点评日期。 \n\n\n
\n\n
请你编写一个解决方案:
\n\nFebruary 2020
平均评分最高 的电影名称。如果出现平局,返回字典序较小的电影名称。字典序 ,即按字母在字典中出现顺序对字符串排序,字典序较小则意味着排序靠前。
\n\n返回结果格式如下例所示。
\n\n\n\n
示例 1:
\n\n\n输入:\nMovies 表:\n+-------------+--------------+\n| movie_id | title |\n+-------------+--------------+\n| 1 | Avengers |\n| 2 | Frozen 2 |\n| 3 | Joker |\n+-------------+--------------+\nUsers 表:\n+-------------+--------------+\n| user_id | name |\n+-------------+--------------+\n| 1 | Daniel |\n| 2 | Monica |\n| 3 | Maria |\n| 4 | James |\n+-------------+--------------+\nMovieRating 表:\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+-------------+--------------+--------------+-------------+\n输出:\nResult 表:\n+--------------+\n| results |\n+--------------+\n| Daniel |\n| Frozen 2 |\n+--------------+\n解释:\nDaniel 和 Monica 都点评了 3 部电影(\"Avengers\", \"Frozen 2\" 和 \"Joker\") 但是 Daniel 字典序比较小。\nFrozen 2 和 Joker 在 2 月的评分都是 3.5,但是 Frozen 2 的字典序比较小。\n\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 55, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__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", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"16.7K\", \"totalSubmission\": \"45.8K\", \"totalAcceptedRaw\": 16688, \"totalSubmissionRaw\": 45846, \"acRate\": \"36.4%\"}", "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, "envInfo": "{\"mysql\":[\"MySQL\",\"
\\u7248\\u672c\\uff1a mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\" Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\" Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\" PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"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\"]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"