← Retention, funnels, cohorts

Cohort matrix (checkout), BY: Feb–Mar 2025, months 0–2

Level: Senior200 XP

Instructions

A cohort is the users from the country 'BY' who signed up (users.signup_at) in one calendar month; take the cohorts of February–March 2025 (signups from February 1, 2025 to March 31, 2025 inclusive). The offset month_offset is the number of calendar months between the signup month and the event month (an event in the signup month has offset 0, in the next month 1, and so on); a user active in a month is a user who has at least one event of type 'checkout' in that month. Build a retention matrix for offsets 0 to 2: for each cohort–offset pair, output cohort_month (the first day of the cohort month), month_offset, active_users (the number of active users in the cohort; each user once) and retention_pct (active_users / cohort size × 100, rounded to 1 decimal place; the cohort size is all its users, including those with no events). Output cells with no active users with active_users = 0. Sort by cohort_month, then month_offset.

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