Skip to content

Tracks and plays per jazz artist without double counting

MediumFreeJoinsGroup and aggregate12 min2 hidden datasets

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_id
  • artist_name
  • tracks: number of rows in tracks for the artist, 0 if none
  • plays: total number of rows in plays across 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.

intUnique id.
dateDay they joined.
textTwo-letter country code.
textfree, premium or family.
artists30 rows in the sample

One row per artist. Key: artist_id.

intUnique id.
textName.
textpop, rock, hip-hop, electronic, jazz or folk.
tracks116 rows in the sample

One row per track. Key: track_id.

intUnique id.
textTrack title.
intMain artist.
intLength.
dateRelease day.
plays6,555 rows in the sample

One row per play. Key: play_id.

bigintUnique id.
intWho listened.
intWhat.
timestampStart time (UTC).
intHow long they listened.
textphone, desktop, speaker or car.

Related questions

Loading the editor and PostgreSQL