Skip to content

Listener tenure in whole months by plan

MediumFull bankDates and timeGroup and aggregate14 min2 hidden datasets

The task

The retention team wants the average tenure of listeners on each plan, as of 2025-06-30.

Tenure is the number of whole months between joined_on and 2025-06-30. A month is whole once the same day of the month has been reached: someone who joined on the 15th has completed one month on the 15th of the next month, and has not on the 14th. Count in calendar months (not blocks of 30 days), so:

  • joined 2025-05-30 gives 1 month
  • joined 2025-05-31 gives 0 months (the 31st never arrives in June)
  • joined 2025-06-30 gives 0 months

Only listeners who joined on or before 2025-06-30 are included.

Return one row per plan that has such listeners:

  • plan
  • listeners: how many listeners are included
  • avg_tenure_months: the average of their whole-month tenures, rounded to 1 decimal place

Sort by plan.

Expected output

planlistenersavg_tenure_months
  • Sorted by plan ascending.
  • Numbers rounded to 1 decimal place.
  • 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