Movie Rating
<p>Table: <code>Movies</code></p>

<pre>
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| movie_id      | int     |
| title         | varchar |
+---------------+---------+
movie_id is the primary key (column with unique values) for this table.
title is the name of the movie.
</pre>

<p>&nbsp;</p>

<p>Table: <code>Users</code></p>

<pre>
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| user_id       | int     |
| name          | varchar |
+---------------+---------+
user_id is the primary key (column with unique values) for this table.
The column &#39;name&#39; has unique values.
</pre>

<p>Table: <code>MovieRating</code></p>

<pre>
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| movie_id      | int     |
| user_id       | int     |
| rating        | int     |
| created_at    | date    |
+---------------+---------+
(movie_id, user_id) is the primary key (column with unique values) for this table.
This table contains the rating of a movie by a user in their review.
created_at is the user&#39;s review date. 
</pre>

<p>&nbsp;</p>

<p>Write a solution to:</p>

<ul>
	<li>Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.</li>
	<li>Find the movie name with the <strong>highest average</strong> rating in <code>February 2020</code>. In case of a tie, return the lexicographically smaller movie name.</li>
</ul>

<p>The&nbsp;result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> 
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  | 
+-------------+--------------+--------------+-------------+
<strong>Output:</strong> 
+--------------+
| results      |
+--------------+
| Daniel       |
| Frozen 2     |
+--------------+
<strong>Explanation:</strong> 
Daniel and Monica have rated 3 movies (&quot;Avengers&quot;, &quot;Frozen 2&quot; and &quot;Joker&quot;) but Daniel is smaller lexicographically.
Frozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.
</pre>

[]
['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')"]
[{"value": "mysql", "text": "MySQL", "defaultCode": "# Write your MySQL query statement below\n"}, {"value": "mssql", "text": "MS SQL Server", "defaultCode": "/* Write your T-SQL query statement below */\n"}, {"value": "oraclesql", "text": "Oracle", "defaultCode": "/* Write your PL/SQL query statement below */\n"}, {"value": "pythondata", "text": "Pandas", "defaultCode": "import pandas as pd\n\ndef movie_rating(movies: pd.DataFrame, users: pd.DataFrame, movie_rating: pd.DataFrame) -> pd.DataFrame:\n    "}, {"value": "postgresql", "text": "PostgreSQL", "defaultCode": "-- Write your PostgreSQL query statement below\n"}]
{"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"}}}
{"mysql": ["MySQL", "<p><code>MySQL 8.0</code>.</p>"], "mssql": ["MS SQL Server", "<p><code>mssql server 2019</code>.</p>"], "oraclesql": ["Oracle", "<p><code>Oracle Sql 11.2</code>.</p>"], "pythondata": ["Pandas", "<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4</p>"], "postgresql": ["PostgreSQL", "<p>PostgreSQL 16</p>"]}
['Database']