Find the top 5 artists by Global Top 10 chart appearances across all their songs

Quick Overview

Join artists, songs and chart entries to find the five artists with the most Global Top 10 appearances across all their songs, with ties broken by artist id. It tests multi-table joins, filtering before aggregation, grouping on a unique key and deterministic top-N queries.

Find the top 5 artists by Global Top 10 chart appearances across all their songs

Company: Spotify

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Three tables describe artists, their songs and the Global chart: each `chart_entries` row is one song's position on one chart date. Find the top 5 artists by number of Global Top 10 appearances (`chart_position <= 10`) across all their songs. Return `artist_name` and `appearance_count`, ordered by `appearance_count` descending, then `artist_id` ascending. ```hint Pick the grouping key Group on the column that identifies an artist uniquely, and check which row ends up fifth when counts tie. ``` ### Input Table(s) `artists` | Column | Type | Meaning | |---|---|---| | artist_id | INT | Artist identifier | | artist_name | VARCHAR(255) | Artist name, not NULL | Primary key: `artist_id`. `songs` | Column | Type | Meaning | |---|---|---| | song_id | INT | Song identifier | | song_title | VARCHAR(255) | Song title, not NULL | | artist_id | INT | Artist who recorded the song | Primary key: `song_id`. Foreign key: `artist_id` references `artists.artist_id`. `chart_entries` | Column | Type | Meaning | |---|---|---| | entry_id | INT | Chart entry identifier | | song_id | INT | Song on the chart | | chart_date | DATE | Date of the chart, not NULL | | chart_position | INT | Position on that date's Global chart (1 is the top), not NULL | Primary key: `entry_id`. Foreign key: `song_id` references `songs.song_id`. ### Output Contract Columns, in this order: | Column | Definition | |---|---| | artist_name | The artist's name | | appearance_count | Number of `chart_entries` rows with `chart_position <= 10` for any of the artist's songs | Order by `appearance_count` descending, then `artist_id` ascending, and return the first 5 rows of that order. `artist_id` is unique, so the order and the cut are fully determined. ### Example `artists` | artist_id | artist_name | |---|---| | 1 | Nova Lane | | 2 | The Static | | 3 | Mira Cole | | 4 | Echo Park Kids | | 5 | Juno Reyes | | 6 | Atlas Grey | | 7 | Silver Fern | `songs` | song_id | song_title | artist_id | |---|---|---| | 101 | Glass Hearts | 1 | | 102 | Midnight Run | 1 | | 103 | Low Tide | 2 | | 104 | Paper Planes | 3 | | 105 | Northern Lights | 4 | | 106 | Slow Burn | 5 | | 107 | Coastline | 6 | | 108 | Quiet Hours | 7 | `chart_entries` | entry_id | song_id | chart_date | chart_position | |---|---|---|---| | 1 | 101 | 2024-06-01 | 1 | | 2 | 103 | 2024-06-01 | 2 | | 3 | 104 | 2024-06-01 | 5 | | 4 | 105 | 2024-06-01 | 7 | | 5 | 102 | 2024-06-01 | 9 | | 6 | 106 | 2024-06-01 | 10 | | 7 | 108 | 2024-06-01 | 12 | | 8 | 101 | 2024-06-08 | 3 | | 9 | 103 | 2024-06-08 | 4 | | 10 | 105 | 2024-06-08 | 6 | | 11 | 107 | 2024-06-08 | 8 | | 12 | 104 | 2024-06-08 | 11 | | 13 | 102 | 2024-06-08 | 15 | | 14 | 108 | 2024-06-08 | 50 | Expected result: | artist_name | appearance_count | |---|---| | Nova Lane | 3 | | The Static | 2 | | Echo Park Kids | 2 | | Mira Cole | 1 | | Juno Reyes | 1 | Nova Lane gets 2 appearances from Glass Hearts and 1 from Midnight Run (its position 15 entry does not count). The Static and Echo Park Kids tie at 2 and are ordered by `artist_id`. Mira Cole, Juno Reyes (position 10 counts) and Atlas Grey tie at 1, and Atlas Grey has the largest `artist_id` of the three, so it falls outside the top 5. Silver Fern never reached the Top 10. ### Constraints and Clarifications - `chart_entries` has at most 10,000 rows, `artists` at most 1,000 and `songs` at most 5,000. - `chart_position` is between 1 and 200. Top 10 means positions 1 to 10, inclusive. - Every qualifying `chart_entries` row is one appearance. A song in the Top 10 on three dates counts three times, and the appearances of all of an artist's songs are added together. - Only artists with at least one Top 10 appearance are returned. If fewer than 5 artists qualify, return fewer rows. - Exactly 5 rows are returned when at least 5 artists qualify, even if the sixth artist has the same count as the fifth. The `artist_id` tiebreak decides who is in. - Two artists can share an `artist_name`. They are different artists and get separate rows. - A chart entry that cannot be matched to an artist (for example, a song with a NULL `artist_id`) is not credited to anyone.

Overview: Join artists, songs and chart entries to find the five artists with the most Global Top 10 appearances across all their songs, with ties broken by artist id. It tests multi-table joins, filtering before aggregation, grouping on a unique key and deterministic top-N queries.

Spotify logo
Spotify
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Three tables describe artists, their songs and the Global chart: each chart_entries row is one song's position on one chart date.

Find the top 5 artists by number of Global Top 10 appearances (chart_position <= 10) across all their songs. Return artist_name and appearance_count, ordered by appearance_count descending, then artist_id ascending.

Input Table(s)

artists

ColumnTypeMeaning
artist_idINTArtist identifier
artist_nameVARCHAR(255)Artist name, not NULL

Primary key: artist_id.

songs

ColumnTypeMeaning
song_idINTSong identifier
song_titleVARCHAR(255)Song title, not NULL
artist_idINTArtist who recorded the song

Primary key: song_id. Foreign key: artist_id references artists.artist_id.

chart_entries

ColumnTypeMeaning
entry_idINTChart entry identifier
song_idINTSong on the chart
chart_dateDATEDate of the chart, not NULL
chart_positionINTPosition on that date's Global chart (1 is the top), not NULL

Primary key: entry_id. Foreign key: song_id references songs.song_id.

Output Contract

Columns, in this order:

ColumnDefinition
artist_nameThe artist's name
appearance_countNumber of chart_entries rows with chart_position <= 10 for any of the artist's songs

Order by appearance_count descending, then artist_id ascending, and return the first 5 rows of that order. artist_id is unique, so the order and the cut are fully determined.

Example

artists

artist_idartist_name
1Nova Lane
2The Static
3Mira Cole
4Echo Park Kids
5Juno Reyes
6Atlas Grey
7Silver Fern

songs

song_idsong_titleartist_id
101Glass Hearts1
102Midnight Run1
103Low Tide2
104Paper Planes3
105Northern Lights4
106Slow Burn5
107Coastline6
108Quiet Hours7

chart_entries

entry_idsong_idchart_datechart_position
11012024-06-011
21032024-06-012
31042024-06-015
41052024-06-017
51022024-06-019
61062024-06-0110
71082024-06-0112
81012024-06-083
91032024-06-084
101052024-06-086
111072024-06-088
121042024-06-0811
131022024-06-0815
141082024-06-0850

Expected result:

artist_nameappearance_count
Nova Lane3
The Static2
Echo Park Kids2
Mira Cole1
Juno Reyes1

Nova Lane gets 2 appearances from Glass Hearts and 1 from Midnight Run (its position 15 entry does not count). The Static and Echo Park Kids tie at 2 and are ordered by artist_id. Mira Cole, Juno Reyes (position 10 counts) and Atlas Grey tie at 1, and Atlas Grey has the largest artist_id of the three, so it falls outside the top 5. Silver Fern never reached the Top 10.

Constraints and Clarifications

  • chart_entries has at most 10,000 rows, artists at most 1,000 and songs at most 5,000.
  • chart_position is between 1 and 200. Top 10 means positions 1 to 10, inclusive.
  • Every qualifying chart_entries row is one appearance. A song in the Top 10 on three dates counts three times, and the appearances of all of an artist's songs are added together.
  • Only artists with at least one Top 10 appearance are returned. If fewer than 5 artists qualify, return fewer rows.
  • Exactly 5 rows are returned when at least 5 artists qualify, even if the sixth artist has the same count as the fifth. The artist_id tiebreak decides who is in.
  • Two artists can share an artist_name . They are different artists and get separate rows.
  • A chart entry that cannot be matched to an artist (for example, a song with a NULL artist_id ) is not credited to anyone.