← SQL workplace practice

Cohorts and customer journeys · Original fictional data · Free files and full answers

Track cumulative conversion with a changing eligible population

For days0 through14 return day,registered_users,purchasers through that day. Users enter the denominator on signup; purchases before signup are excluded. One user counts once. Sort 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

  1. For days0 through14 return day,registered_users,purchasers through that day. Users enter the denominator on signup; purchases before signup are excluded. One user counts once. Sort day.
  2. 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.
  3. 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 day, registered_users, purchasers. Sort order follows the task. Output has 15 rows; an empty CSV field means NULL.

Source data

users

8 source rows · Download users CSV

id INTEGERsignup_day INTEGERchannel TEXT
10search
20search
31email
42email
55social
68search
712social
814email

activity

19 source rows · Download activity CSV

id INTEGERuser_id INTEGERday INTEGERkind TEXTcents INTEGER
11-1visit0
210visit0
311purchase1000
411visit0
518purchase2000
621visit0
723purchase500
8212visit0
931visit0
1032visit0
1138purchase900
1243purchase1200
1344purchase600
14413purchase300
1555visit0
16513purchase800
1769purchase400
18712visit0
19714purchase700
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.

Download complete SQLite setup

A method you can reuse

  1. For days0 through14 return day,registered_users,purchasers through that day. Users enter the denominator on signup; purchases before signup are excluded. One user counts once. Sort day.
  2. For the first output record, day = 0; registered_users = 2; purchasers = 0.
  3. Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

Watch for this wrong turn

Using the final user count on earlier days places future registrations in the conversion denominator.

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 RECURSIVE d(day) AS (SELECT 0 UNION ALL SELECT day+1 FROM d WHERE day<14) SELECT day,(SELECT COUNT(*) FROM users u WHERE u.signup_day<=d.day) registered_users,(SELECT COUNT(*) FROM users u WHERE u.signup_day<=d.day AND EXISTS(SELECT 1 FROM activity a WHERE a.user_id=u.id AND a.kind='purchase' AND a.day>=u.signup_day AND a.day<=d.day)) purchasers FROM d ORDER BY day;
"day","registered_users","purchasers"
"0","2","0"
"1","3","1"
"2","4","1"
"3","4","3"
"4","4","3"
"5","5","3"
"6","5","3"
"7","5","3"
"8","6","4"
"9","6","5"
"10","6","5"
"11","6","5"
"12","7","5"
"13","7","6"
"14","8","7"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects