Listener quartiles by May listening time
The task
The product team wants to compare heavy and light listeners. Take every listener with at least one play in May 2025 (from 2025-05-01 00:00:00 up to, but not including, 2025-06-01 00:00:00) and add up their seconds_played for the month.
Order the listeners from the most seconds to the fewest, with the lower listener_id first when totals are equal, and split them into 4 quartiles of as equal size as possible. Quartile 1 holds the heaviest listeners. When the number of listeners is not a multiple of 4, the first quartiles each get one extra listener (22 listeners split 6, 6, 5, 5).
Return one row per quartile: quartile (1 to 4), listeners (how many are in it) and total_seconds (the sum of their May seconds). Sort by quartile ascending.
Expected output
quartilelistenerstotal_seconds- Sorted by quartile 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
- How far each artist climbed or fell from April to Mayhard
- Top two artists each month by listening timemedium
- Favourite spending category per customer, counted by segmenthard
- First order value by acquisition channelmedium
- Genre of each listener's first playmedium
- Months each merchant ranked in the top three for spendmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL