Listener tenure in whole months by plan
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:
planlisteners: how many listeners are includedavg_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.
| 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