Tracks and plays per jazz artist without double counting
The task
The label relations team reviews every artist whose genre is 'jazz'. For each one they want the size of the catalog and how much it is played.
Return:
artist_idartist_nametracks: number of rows intracksfor the artist, 0 if noneplays: total number of rows inplaysacross all of the artist's tracks, 0 if none
An artist with no tracks, or tracks that were never played, must still appear. Sort by plays descending, then artist_id ascending.
Expected output
artist_idartist_nametracksplays- Sorted by plays descending, then artist_id 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