Weekly sign-up cohorts and next-week buyers
The task
The marketing team tracks whether new sign-ups come back to buy. Group users into weekly cohorts and measure repeat buying in the following week.
Rules:
- A user's cohort is the calendar week of
signups.signed_up_at. Weeks run Monday to Sunday, andcohort_weekis the Monday. - A user is retained if they made at least one purchase (
purchases.purchased_at) in the next calendar week, Monday to Sunday. Purchases in the cohort's own week do not count. - Count users, not purchases.
- Only include a cohort when its next week is complete in the data: the Sunday that ends the next week must be on or before the date of the latest
purchased_atinpurchases. - A cohort with no retained users still appears, with 0.
Return cohort_week, cohort_size, retained_users and retention_pct (retained users as a percentage of the cohort, rounded to 1 decimal place). Sort by cohort_week.
Expected output
cohort_weekcohort_sizeretained_usersretention_pct- Sorted by cohort_week ascending.
- Numbers rounded to 1 decimal place.
- Checked on the sample and on 3 hidden datasets. How grading works
Tables Marketing team · click a name to insert it
campaigns10 rows in the sample
One row per campaign. Key: campaign_id.
| int | Unique id. | |
| text | Name. | |
| text | search, social, video, email or affiliate. | |
| date | First day live. | |
| date | Last day live. NULL if still running. | |
| numeric(10,2) | Budget per day, USD. |
ad_daily969 rows in the sample
One row per campaign per day it served ads. Days with no delivery have no row. Key: campaign_id, day.
| int | The campaign. | |
| date | The day. | |
| int | Times an ad was shown. | |
| int | Clicks. | |
| numeric(10,2) | Money spent, USD. |
signups2,108 rows in the sample
One row per new user. campaign_id is the campaign credited with the sign-up. Key: user_id.
| int | Unique id. | |
| timestamp | When they signed up (UTC). | |
| int | Credited campaign. NULL for organic sign-ups. | |
| text | Two-letter country code. |
purchases2,294 rows in the sample
One row per paid order by a user. Key: purchase_id.
| int | Unique id. | |
| int | Buyer. | |
| timestamp | When (UTC). | |
| numeric(10,2) | Order value, USD. |
Related questions
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL