Listeners whose first play was on a speaker
The task
The devices team thinks smart speakers bring in a different kind of listener. To test it, they want to know, for each plan, how many listeners started on a speaker.
A listener's first play is the one with the earliest played_at. If two plays share that time, the one with the lower play_id is first. Only listeners with at least one play are counted anywhere in this question.
Return one row per plan that has at least one listener with a play:
planlisteners: listeners on that plan with at least one playspeaker_first: of those, how many haddevice = 'speaker'on their first playpct_speaker_first:speaker_firstas a percentage oflisteners, rounded to 1 decimal place
Sort by plan.
Expected output
planlistenersspeaker_firstpct_speaker_first- 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