Free and paid listeners per genre
The task
The product team wants to know which genres reach people on the free plan and which reach paying people. A listener is paid when listeners.plan is 'premium' or 'family', and free when it is 'free'.
For every genre that has at least one artist, count the distinct listeners who played at least one track by an artist of that genre. A play counts whatever its length.
Return:
genrefree_listeners: distinct free listeners who played the genre, 0 if nonepaid_listeners: distinct paid listeners who played the genre, 0 if none
Sort by genre.
Expected output
genrefree_listenerspaid_listeners- Sorted by 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
- Listeners who played both jazz and folkmedium
- Plays in the first two weeks for April joinerseasy
- Tickets per response band from a band lookup tablemedium
- Tracks and plays per jazz artist without double countingmedium
- Trips from brand-new riders, by cityeasy
- April spend and cost per click for search and socialeasy
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL