Artist rank change from May to June
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_idartist_namerank_may: the artist's rank in May, or NULL if they had no plays in Mayrank_june: the artist's rank in June, or NULL if they had no plays in Juneplaces_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.
| int | Unique id. | |
| date | Day they joined. | |
| text | Two-letter country code. | |
| text | free, premium or family. |
artists30 rows in the sample
One row per artist. Key: artist_id.
| int | Unique id. | |
| text | Name. | |
| text | pop, rock, hip-hop, electronic, jazz or folk. |
tracks116 rows in the sample
One row per track. Key: track_id.
| int | Unique id. | |
| text | Track title. | |
| int | Main artist. | |
| int | Length. | |
| date | Release day. |
plays6,555 rows in the sample
One row per play. Key: play_id.
| bigint | Unique id. | |
| int | Who listened. | |
| int | What. | |
| timestamp | Start time (UTC). | |
| int | How long they listened. | |
| text | phone, desktop, speaker or car. |
Related questions
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL