Skip to content

Artist rank change from May to June

HardFull bankPeriod over periodRanking and top NJoins28 min2 hidden datasets

The task

Editorial publishes a "movers" list of artists whose chart position changed between May and June 2025.

For each month, rank artists by their number of plays that month (a play belongs to the artist of its track; use played_at from the first day of the month up to the first day of the next). The artist with the most plays is rank 1. Artists with equal plays share a rank, and the next rank is skipped (1, 2, 2, 4). Only artists with at least one play in that month are ranked in that month.

Return one row for every artist who has at least one play in May or in June:

  • artist_id
  • artist_name
  • rank_may: the artist's rank in May, or NULL if they had no plays in May
  • rank_june: the artist's rank in June, or NULL if they had no plays in June
  • places_gained: rank_may - rank_june (positive means the artist moved up the chart), or NULL when either rank is NULL

Sort by places_gained descending with NULLs last, then artist_id ascending.

Expected output

artist_idartist_namerank_mayrank_juneplaces_gained
  • Sorted by places_gained descending, then artist_id ascending.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Music streaming service · click a name to insert it

listeners180 rows in the sample

One row per listener account. Key: listener_id.

intUnique id.
dateDay they joined.
textTwo-letter country code.
textfree, premium or family.
artists30 rows in the sample

One row per artist. Key: artist_id.

intUnique id.
textName.
textpop, rock, hip-hop, electronic, jazz or folk.
tracks116 rows in the sample

One row per track. Key: track_id.

intUnique id.
textTrack title.
intMain artist.
intLength.
dateRelease day.
plays6,555 rows in the sample

One row per play. Key: play_id.

bigintUnique id.
intWho listened.
intWhat.
timestampStart time (UTC).
intHow long they listened.
textphone, desktop, speaker or car.

Related questions

Loading the editor and PostgreSQL