Events in the 10 minutes before each purchase
The task
Product wants to know how busy a user was just before buying. For every purchase event in June 2025 (from 2025-06-01 up to, but not including, 2025-07-01), count that user's events in the 10 minutes up to and including the purchase.
An event counts when it belongs to the same user, whatever its event_name, and its occurred_at is between 10 minutes before the purchase and the purchase time, both ends included. That includes the purchase event itself, and any other event of the user with exactly the same occurred_at as the purchase.
Return:
event_id: the purchase eventuser_idoccurred_atevents_last_10_min: the number of events counted
Sort by occurred_at, then event_id.
Expected output
event_iduser_idoccurred_atevents_last_10_min- Sorted by occurred_at ascending, then event_id ascending.
- 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
- Cumulative revenue by day, including quiet dayseasy
- Hours since the customer's previous ticketmedium
- Rolling seven-day spend when days are missinghard
- Running count of distinct buyers by first purchase monthmedium
- Seven-day moving average of sign-upshard
- Time until a rider requests again after cancellingmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL