Users whose carts turn into purchases within 30 minutes
The task
The checkout team wants to find users who buy quickly after adding something to their cart.
An add_to_cart event is a quick cart if the same user fires a purchase event after it, at most 30 minutes later. The purchase must be strictly after the cart event, and exactly 30 minutes later still counts. Count each cart event once, even when the user makes several purchases in that window.
Return the users with at least 2 quick carts: user_id and quick_carts (their number of quick cart events). Sort by quick_carts descending, then user_id ascending.
Expected output
user_idquick_carts- Sorted by quick_carts descending, then user_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
- Colleagues hired in the same month and departmenteasy
- Repeat tickets from the same customer within a weekeasy
- Employees paid more than their managermedium
- How many drivers in the same city rate higherhard
- Products bought together in the same ordermedium
- Raises of 9.5 percent or more over the previous salaryhard
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL