86. Top song in the US

easy spotify

*****************************************************************************************

Table 1: song

  col_name   | col_type
-------------+--------------------------
   song_id   | bigint
   title     | varchar(1000)
   artist_id | bigint

Table 2: song_plays

Number of times a song is played (streamed), aggregated on daily basis.

  col_name   | col_type
-------------+--------------------------
 date        | date
 country     | varchar(2)
 song_id     | bigint
 num_plays   | bigint

Sample results

title
------------
Eminence Front

Solution postgres

SELECT S.title
FROM song_plays d   
INNER JOIN song S
ON S.song_id = d.song_id
WHERE d.country = 'US'
AND d.date = '2021-01-01'
ORDER BY num_plays DESC
LIMIT 1
    

Explanation

This query selects the title of the song that was played the most in the US on January 1st, 2021. It does this by joining the song_plays table with the song table on the song_id column. It then filters the results to only include plays that occurred in the US on January 1st, 2021. The results are sorted in descending order based on the number of plays, and the limit is set to 1, meaning only the top result is returned.

Expected results


More Spotify questions

ID Title Level FTPR
87 Top song in the US and UK spotify medium
9%
88 Top song report spotify medium
22%
89 Top 5 artists in the US spotify medium
13%
90 Top artist report spotify medium
21%
91 same day friend request acceptance rate spotify easy
13%
92 Acceptance rate first week of 2021 spotify easy
14%