Retention table for months 0 to 3
The task
The growth team wants the raw numbers behind a retention triangle, in long format: one row per sign-up cohort and month number.
A user's cohort is the calendar month of users.signed_up_at. Month number 0 is the cohort's own month, 1 is the next calendar month, and so on up to 3. A user is retained in a month if they fired at least one event in events during that calendar month.
Rules:
- Show every cohort with every month number from 0 to 3, even when nobody was retained (
retained_usersis then 0). - Leave out a cohort and month number when that calendar month is later than the month of the most recent event in
events: the data does not cover it yet. - Count users, not events.
Return cohort_month (the first day of the cohort's month), month_number, cohort_size (users in the cohort, repeated on each row) and retained_users. Sort by cohort_month, then month_number.
Expected output
cohort_monthmonth_numbercohort_sizeretained_users- Sorted by cohort_month ascending, then month_number ascending.
- Checked on the sample and on 3 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
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL