Skip to content

Events in the 10 minutes before each purchase

HardFull bankRunning totals, LAG and LEADDates and time20 min2 hidden datasets

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 event
  • user_id
  • occurred_at
  • events_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.

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