Top 5 Artists

ASKED IN INTERVIEW
4pts
Spotify

Problem Statement

Spotify wants to recognize the most successful artists on their platform.

Write an SQL query to find the top 5 artists whose songs appear most frequently in the Top 10 of the global_song_rank table.

Rules:

  • Only consider songs with a rank of 10 or better (1 to 10).
  • If multiple artists have the same number of Top 10 appearances, they should receive the same rank.
  • Use DENSE_RANK() so that if there are ties, the next rank in the sequence is not skipped.
  • Output the artist_name and the artist_rank.
  • Results must be sorted by artist_rank in ascending order, then by artist_name in ascending order.
Tests your understanding of
Ranking, Window Functions, JOIN and Aggregation

Input Tables

artists
artist_id(INTEGER)artist_name(VARCHAR)
1Artist A
2Artist B
3Artist C
4Artist D
5Artist E
6Artist F
songs
song_id(INTEGER)artist_id(INTEGER)
1011
1021
2012
3013
4014
5015
6016
global_song_rank
day(INTEGER)song_id(INTEGER)rank(INTEGER)
11011
11022
12013
21011
23015
340110
350110
360111

Expected Output

artist_name(VARCHAR)artist_rank(INTEGER)
Artist A1
Artist B2
Artist C2
Artist D2
Artist E2

Tags

MediumASKED IN INTERVIEWRankingWindow FunctionsJOINAggregation
20-25 min
40%

Hints