Median hours from sign-up to first purchase
The task
Growth wants to know how long new users take to buy for the first time, by platform. A few slow buyers pull the average far above what a typical user does, so report both the median and the average.
For each user, take the time from users.signed_up_at to their first purchase event, in hours. Users who never purchased are left out. Measure only each user's first purchase, not later ones.
Return one row per platform that has at least one buyer:
platformbuyers: how many users made a purchasemedian_hours: the median of those hours, rounded to 1 decimal place. With an even number of buyers, the median is the average of the two middle values.avg_hours: the mean of those hours, rounded to 1 decimal place
Sort by platform.
Expected output
platformbuyersmedian_hoursavg_hours- Sorted by platform ascending.
- Numbers rounded to 1 decimal place.
- 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.
| int | Unique id. | |
| timestamp | Sign-up time (UTC). | |
| text | Two-letter country code. | |
| text | ios, android or web. | |
| text | organic, paid, referral or partner. NULL when unknown. |
events7,616 rows in the sample
One row per tracked event. Key: event_id.
| bigint | Unique id. | |
| int | Who fired it. | |
| text | app_open, search, view_item, add_to_cart, begin_checkout, purchase or share. | |
| timestamp | When (UTC). | |
| text | Session 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.
| int | The user. | |
| text | new_onboarding or one_tap_checkout. | |
| text | control or treatment. | |
| timestamp | When the user was assigned (UTC). |
Related questions
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL