Session Funnel Order
Start Timer
0:00:00
We’re given an events table where each row is an action a user took, and the action is a search, a view_item or a purchase. Write a query that returns the distinct users who did a search, then a view, then a purchase, in that strict chronological order within a single session.
Rules
- A session is defined per user as a run of consecutive events where the gap between one event and the next is less than 30 minutes. A gap of 30 minutes or more starts a new session.
- A user qualifies if some search, some later view_item and some even later purchase exist in the same session, regardless of other events of those types occurring earlier or in between.
Example:
Input:
events table
| Column | Type |
|---|---|
id |
INTEGER |
user_id |
INTEGER |
event_type |
VARCHAR |
created_at |
DATETIME |
Output:
| Column | Type |
|---|---|
user_id |
INTEGER |
.
.
.
.
.
.
.
.
.
Comments