Skip to content

Purchase value spread (interquartile range) by platform

MediumFull bankMedians and percentilesJoins14 min2 hidden datasets

The task

The pricing team wants to see how spread out order values are on each platform, without letting a few giant orders distort the picture. The interquartile range (IQR) is the distance between the 25th and 75th percentiles.

Use events rows with event_name = 'purchase' and a non-NULL revenue, and take the platform from the user's row in users. For each platform, compute the 25th and 75th percentiles of revenue with linear interpolation (the continuous percentile).

Return platform, purchases (the purchases counted), q1 (25th percentile), q3 (75th percentile) and iqr (q3 minus q1, computed before rounding). Round q1, q3 and iqr to 2 decimal places. Platforms with no such purchases are not listed. Sort by platform.

Expected output

platformpurchasesq1q3iqr
  • Sorted by platform ascending.
  • Numbers rounded to 2 decimal places.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Mobile shopping app · click a name to insert it

users360 rows in the sample

One row per user. Key: user_id.

intUnique id.
timestampSign-up time (UTC).
textTwo-letter country code.
textios, android or web.
textorganic, paid, referral or partner. NULL when unknown.
events7,616 rows in the sample

One row per tracked event. Key: event_id.

bigintUnique id.
intWho fired it.
textapp_open, search, view_item, add_to_cart, begin_checkout, purchase or share.
timestampWhen (UTC).
textSession the event belongs to. NULL for a few events sent from the background.
numeric(10,2)Order value for purchase events, NULL otherwise.
experiment_assignments349 rows in the sample

Which variant each user saw in each experiment. Key: user_id, experiment.

intThe user.
textnew_onboarding or one_tap_checkout.
textcontrol or treatment.
timestampWhen the user was assigned (UTC).

Related questions

Loading the editor and PostgreSQL