Cohorts and customer journeys · Original fictional data · Free files and full answers
Measure revenue concentration within each acquisition cohort
For each signup cohort with purchases, return signup_day,top_user_id,top_user_revenue,cohort_revenue. Pick the highest total purchaser, ties smaller user_id. Sort signup_day.
Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.
Your output contract
- For each signup cohort with purchases, return signup_day,top_user_id,top_user_revenue,cohort_revenue. Pick the highest total purchaser, ties smaller user_id. Sort signup_day.
- Return exactly the declared columns and order. Money uses integer cents; time and date units follow the task and field dictionary. NULL is unknown and differs from numeric zero.
- These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.
Return columns exactly as signup_day, top_user_id, top_user_revenue, cohort_revenue. Sort order follows the task. Output has 6 rows; an empty CSV field means NULL.
Source data
users
8 source rows · Download users CSV
| id INTEGER | signup_day INTEGER | channel TEXT |
|---|---|---|
| 1 | 0 | search |
| 2 | 0 | search |
| 3 | 1 | |
| 4 | 2 | |
| 5 | 5 | social |
| 6 | 8 | search |
| 7 | 12 | social |
| 8 | 14 |
activity
19 source rows · Download activity CSV
| id INTEGER | user_id INTEGER | day INTEGER | kind TEXT | cents INTEGER |
|---|---|---|---|---|
| 1 | 1 | -1 | visit | 0 |
| 2 | 1 | 0 | visit | 0 |
| 3 | 1 | 1 | purchase | 1000 |
| 4 | 1 | 1 | visit | 0 |
| 5 | 1 | 8 | purchase | 2000 |
| 6 | 2 | 1 | visit | 0 |
| 7 | 2 | 3 | purchase | 500 |
| 8 | 2 | 12 | visit | 0 |
| 9 | 3 | 1 | visit | 0 |
| 10 | 3 | 2 | visit | 0 |
| 11 | 3 | 8 | purchase | 900 |
| 12 | 4 | 3 | purchase | 1200 |
| 13 | 4 | 4 | purchase | 600 |
| 14 | 4 | 13 | purchase | 300 |
| 15 | 5 | 5 | visit | 0 |
| 16 | 5 | 13 | purchase | 800 |
| 17 | 6 | 9 | purchase | 400 |
| 18 | 7 | 12 | visit | 0 |
| 19 | 7 | 14 | purchase | 700 |
Field dictionary and schema
users: id INTEGER — Stable source record identifier; not a row position. signup_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation. channel TEXT — Literal business key or category label. Match exactly and retain NULL where present. activity: id INTEGER — Stable source record identifier; not a row position. user_id INTEGER — Foreign business-record identifier; match to the named source key. day INTEGER — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics. kind TEXT — Literal business key or category label. Match exactly and retain NULL where present. cents INTEGER — Signed integer currency cents.
A method you can reuse
- For each signup cohort with purchases, return signup_day,top_user_id,top_user_revenue,cohort_revenue. Pick the highest total purchaser, ties smaller user_id. Sort signup_day.
- For the first output record, signup_day = 0; top_user_id = 1; top_user_revenue = 3000; cohort_revenue = 3500.
- Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.
Watch for this wrong turn
Ranking individual payment events can miss a customer whose several payments form the largest cohort contribution.
Run and check in SQLite
Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.
Complete worked SQL and expected output
WITH u AS (SELECT u.signup_day,u.id,SUM(a.cents) revenue FROM users u JOIN activity a ON a.user_id=u.id AND a.kind='purchase' AND a.day>=u.signup_day AND a.day<=14 GROUP BY u.signup_day,u.id), r AS (SELECT *,SUM(revenue) OVER(PARTITION BY signup_day) total,ROW_NUMBER() OVER(PARTITION BY signup_day ORDER BY revenue DESC,id) n FROM u) SELECT signup_day,id top_user_id,revenue top_user_revenue,total cohort_revenue FROM r WHERE n=1 ORDER BY signup_day;
"signup_day","top_user_id","top_user_revenue","cohort_revenue" "0","1","3000","3500" "1","3","900","900" "2","4","2100","2100" "5","5","800","800" "8","6","400","400" "12","7","700","700"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects