Top Streamed Songs

Start Timer

0:00:00

Upvote
5
Downvote
Save question
View comments

Let’s say at Spotify we have a streams table where each row is one play of a song, with the listener’s country and when the stream happened. Write a query that returns the top 10 most streamed songs in each country over the last 30 days, ranked by the number of streams within each country.

Rules - The last 30 days covers whole calendar days from 29 days before the latest streamed_at date in the table through that date, inclusive, ignoring time of day. - The latest date is taken over all rows in the table, including rows where country is NULL. - Ignore streams where country is NULL. - If two songs in a country have the same stream count, break the tie by the lower song_id. - Order the output by country ascending, then stream_count descending, then song_id ascending.

Example:

Input:

streams table

Column Type
id INTEGER
song_id INTEGER
country VARCHAR
streamed_at DATETIME

Output:

Column Type
country VARCHAR
song_id INTEGER
stream_count INTEGER
.
.
.
.
.


Comments

Loading comments