Skip to content

Median listen length, continuous and discrete

EasyFull bankMedians and percentilesGroup and aggregate8 min2 hidden datasets

The task

The audio team reports a median listen length per device and wants to see how much the choice of percentile function matters.

A play counts as a listen when seconds_played is at least 30 (30 itself counts). Ignore shorter plays everywhere in this question.

For each device, return:

  • device
  • listens: number of listens
  • median_cont: the continuous median of seconds_played (interpolates, so an even number of listens gives the average of the two middle values), rounded to 1 decimal place
  • median_disc: the discrete median, which is an actual seconds_played value (the first value whose cumulative share reaches 50 percent)

Sort by device.

Expected output

devicelistensmedian_contmedian_disc
  • Sorted by device 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