SQL
All Top 50 SQL Interview Questions#49
Dual Metric Aggregation with UNION ALL in SQL
MediumAmazonInterview Question #49
Asked at AmazonGiven `movies`, `users`, and `movie_rating`, write a query to find: 1) the user who has rated the greatest number of movies (tie-break by user name alphabetical); 2) the movie with the highest average rating in February 2026 (tie-break by title).
Input Table: movie_rating
3 rows preview| movie_id | user_id | rating | created_at |
|---|---|---|---|
| 1 | 1 | 3 | 2026-02-12 |
| 2 | 1 | 4 | 2026-02-15 |
| 1 | 2 | 5 | 2026-02-14 |
Expected Output Structure2 rows
| results |
|---|
| User One |
| Movie One |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.