← Practice

add_to_cart→purchase (3 steps): May 2025, android, 12 min

Level: SeniorTopic: Retention, funnels, cohorts200 XP

Instructions

A funnel within one session (events.session_id), steps in order: 1) 'add_to_cart', 2) 'checkout', 3) 'purchase'. Consider the events of users of the platform 'android' with event_time in May 2025; events without session_id belong to no session and are not counted. The time of step 1 in a session is the time of its first event of the type of step 1. A session passes step k (k ≥ 2) if it has an event of the type of step k no earlier than the time of step k − 1 and no later than 12 minutes after it; the time of step k is the first such event. A user passes a step if at least one of their sessions passed it; each user is counted once. Output step_no (1, 2, …), step (the event type of the step), users (the number of users who passed the step), pct_of_prev (users / users of the previous step × 100; NULL for the first step) and pct_of_first (users / users of the first step × 100); round both percentages to 1 decimal place. Sort by step_no.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

events.user_id (0…N) ↔ users.id (1…1)purchases.user_id (0…N) ↔ users.id (1…1)eventsPKidintegerFKuser_idintegerpurchasesPKidintegerFKuser_idintegerusersPKidinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneevents.user_id → users.id
  • N:1Many-to-onepurchases.user_id → users.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema