Most played genre for each plan and device
The task
The playlist team wants to know the most common genre for each kind of listening session. For every combination of listener plan and play device, find the genre with the most plays.
- Count only plays with
seconds_playedof 60 or more. - A play's genre is the genre of its track's artist. A play's plan is the plan of its listener.
- If two or more genres tie for the most plays in a combination, return all of them.
- A combination with no counted plays does not appear.
Return plan, device, genre and plays (the number of counted plays of that genre in that combination).
Sort by plan, then device, then genre, all ascending.
Expected output
plandevicegenreplays- Sorted by plan ascending, then device ascending, then genre 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