Interview Query

Top 3 Users

8
Have you seen this question before?

Let’s say you work at a file-hosting website. You have information on user’s daily downloads in the download_facts table

Use the window function RANK to display the top three users by downloads each day. Order your data by date, and then by daily_rank

Example:

Input:

download_facts table

Column Type
user_id INTEGER
date DATE
downloads INTEGER

Output:

Column Type
daily_rank INTEGER
user_id INTEGER
date DATE
downloads INTEGER
Next question: Upsell Transactions
.....
MySQL 8.0.17
Loading editor
Use Shift + Enter to run query