Skip to content

Listener quartiles by May listening time

MediumFull bankRanking and top NGroup and aggregate14 min2 hidden datasets

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.

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