Skip to content

Plays per device for each plan

EasyFull bankConditional aggregationJoins9 min2 hidden datasets

The task

The product team wants to know which devices each subscription plan listens on.

A counted play is a row in plays with seconds_played of at least 30. Shorter plays are skips and are ignored.

Return one row per listener plan (every plan that appears in listeners, even if its listeners have no counted plays) with:

  • plan
  • phone: counted plays on a phone
  • desktop: counted plays on a desktop
  • speaker: counted plays on a speaker
  • car: counted plays in a car

Show 0 where a plan has no counted plays on a device. Sort by plan ascending.

Expected output

planphonedesktopspeakercar
  • Sorted by plan 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