Skip to content

How far each artist climbed or fell from April to May

HardFull bankRanking and top NPeriod over periodGroup and aggregate25 min3 hidden datasets

The task

The charts team publishes a monthly artist ranking and wants to show movement. For each of April 2025 and May 2025, add up the seconds_played of every artist's tracks (a play belongs to the month of played_at) and rank all artists that had at least one play that month, most seconds first. Artists with the same total share a rank, and the next rank skips ahead (1, 1, 3).

Return the artists that were ranked in both months, with:

  • artist_name
  • april_rank
  • may_rank
  • places_gained: april_rank minus may_rank, so a positive number means the artist moved up the chart.

Ranks are computed among all artists with plays that month, including ones that were only ranked in one of the two months. Sort by places_gained descending, then artist_name ascending.

Expected output

artist_nameapril_rankmay_rankplaces_gained
  • Sorted by places_gained descending, then artist_name ascending.
  • Checked on the sample and on 3 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