Skip to content

Listeners whose first play was on a speaker

The task

The devices team thinks smart speakers bring in a different kind of listener. To test it, they want to know, for each plan, how many listeners started on a speaker.

A listener's first play is the one with the earliest played_at. If two plays share that time, the one with the lower play_id is first. Only listeners with at least one play are counted anywhere in this question.

Return one row per plan that has at least one listener with a play:

  • plan
  • listeners: listeners on that plan with at least one play
  • speaker_first: of those, how many had device = 'speaker' on their first play
  • pct_speaker_first: speaker_first as a percentage of listeners, rounded to 1 decimal place

Sort by plan.

Expected output

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