Listener device habits by plan
The task
The product team wants to know, for each plan, how many listeners are active and how widely they use their devices. Count listeners, not plays.
Return one row per plan in listeners with:
planlisteners: number of listeners on the plan, including those with no playsactive_listeners: listeners with at least one row inplayscar_listeners: listeners with at least one play on thecardevice lasting 30 seconds or more (seconds_played >= 30); shorter car plays are skips and do not countbroad_listeners: listeners who have played on 3 or more different devices
A plan with no active listeners shows 0 in the last three columns. Sort by plan ascending.
Expected output
planlistenersactive_listenerscar_listenersbroad_listeners- Sorted by plan 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