Plays per device for each plan
The task
The product team wants to know which devices each subscription plan listens on.
A counted play is a row in plays with seconds_played of at least 30. Shorter plays are skips and are ignored.
Return one row per listener plan (every plan that appears in listeners, even if its listeners have no counted plays) with:
planphone: counted plays on a phonedesktop: counted plays on a desktopspeaker: counted plays on a speakercar: counted plays in a car
Show 0 where a plan has no counted plays on a device. Sort by plan ascending.
Expected output
planphonedesktopspeakercar- 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