Build revenue by signup cohort and relative week
Original fictional practice · CC BY 4.0 · 2026-11-11

TASK
For valid purchases through day14, group by signup_day and integer week_offset=(purchase_day-signup_day)/7. Return signup_day,week_offset,revenue_cents sorted both. Include only observed purchase cells.

OUTPUT
signup_day, week_offset, revenue_cents

RULES
For valid purchases through day14, group by signup_day and integer week_offset=(purchase_day-signup_day)/7. Return signup_day,week_offset,revenue_cents sorted both. Include only observed purchase cells.
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.

FIELD DICTIONARY
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.

METHOD
For valid purchases through day14, group by signup_day and integer week_offset=(purchase_day-signup_day)/7. Return signup_day,week_offset,revenue_cents sorted both. Include only observed purchase cells.
For the first output record, signup_day = 0; week_offset = 0; revenue_cents = 1500.
Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

COMMON WRONG TURN
Calendar week groups mix users at different lifecycle ages and do not form a relative cohort matrix.

RESULT CHECK
For the first output record, signup_day = 0; week_offset = 0; revenue_cents = 1500.

Use setup.sql in a fresh SQLite database and run your own SELECT or WITH. reference.sql and expected.csv contain the full worked answer. All CSVs have UTF-8 headers; empty output fields represent NULL. The browser executes SQLite, not Excel formulas. No spreadsheet function engine is claimed.
