Skip to content

Plays, listeners and hours by genre

EasyFreeGroup and aggregateJoinsNULL handling10 min2 hidden datasets

The task

The content team wants one line of listening stats per genre. A play belongs to the genre of its track's artist.

Return:

  • genre
  • plays: the number of rows in plays
  • listeners: how many different listeners played that genre
  • hours: total seconds_played divided by 3600, rounded to 1 decimal place
  • avg_seconds: the average seconds_played per play, rounded to 1 decimal place

Every genre that has at least one artist must appear. A genre with no plays shows 0 for plays, listeners and hours, and NULL for avg_seconds.

Sort by plays descending, then genre ascending.

Expected output

genreplayslistenershoursavg_seconds
  • Sorted by plays descending, then genre ascending.
  • Numbers rounded to 1 decimal place.
  • 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