Data Modelling · Free · 25 min · Intermediate
Why did last month’s territory revenue change?
Write two territory reports from the same order lines: one at sale time and one at the supplied effective-as-of timestamp. Reconcile a backdated correction without losing or duplicating facts.
Original fictional teaching example. Uses SQLite in your browser; no warehouse update, sign-in, paid service or cloud completion.
Task and report rules
Prerequisites: SELECT, JOIN, GROUP BY, fact grain and UTC timestamp comparison. Finance wants territory at each sale; planning wants territory effective at 2026-02-15 00:00:00 UTC for every line.
- One fact is
(order_id, line_id), not one order. O2 has two legitimate lines. - Return exactly
territory, total_amount, line_count, in that column order, one row per territory. Row order does not matter; duplicate rows and fractional totals do. - Include every fact once. Missing history becomes
Unknown. Amounts are fictional integer units; no refunds, tax, FX or status filter. - Intervals include
valid_from, excludevalid_to; NULL end is open. Fixed-format UTC timestamps compare lexically. Overlap anywhere for a customer blocks both reports, even if no fact lies inside it. - The as-of instant is effective time, not loaded time or proof of what was previously published. Matching these six disclosed examples does not establish unseen transfer or mastery.
Complete input data
Visible six-line fact with exact boundary, two lines in O2, and missing C3 dimension.
Selected source: 6 lines / 520 units. Each report must conserve this selected source.
Correction moves C1's North end and South start to 9 January at noon. Only O1's 100 units move historically; both reports still total six lines / 520 units. Selecting inputs preserves both query drafts and invalidates previous checks.
orders — order_id TEXT, line_id INTEGER, customer_id TEXT, sale_ts TEXT UTC, amount INTEGER
| order_id | line_id | customer_id | sale_ts | amount |
|---|---|---|---|---|
| O0 | 1 | C1 | 2026-01-09 10:00:00 | 60 |
| O1 | 1 | C1 | 2026-01-09 23:59:59 | 100 |
| O2 | 1 | C1 | 2026-01-10 00:00:00 | 200 |
| O2 | 2 | C1 | 2026-01-10 00:00:00 | 50 |
| O3 | 1 | C2 | 2026-01-08 00:00:00 | 80 |
| O4 | 1 | C3 | 2026-01-11 00:00:00 | 30 |
territory_history — customer_id TEXT, territory TEXT, valid_from TEXT UTC, valid_to TEXT UTC or NULL
| customer_id | territory | valid_from | valid_to |
|---|---|---|---|
| C1 | North | 2026-01-01 00:00:00 | 2026-01-10 00:00:00 |
| C1 | South | 2026-01-10 00:00:00 | NULL |
| C2 | West | 2026-01-01 00:00:00 | NULL |
At sale time
Resolve territory using each order line's sale_ts.
As of 15 February
Resolve territory at 2026-02-15 00:00:00 UTC for every order line.
Run checks the selected disclosed snapshot. Both editors are independent.
Device-only drafts
Save both editors, snapshot and assistance state in this browser. No account or cloud save.
Loading this device's draft…
Help, in stages
Hints and the worked example are optional. Input data never requires reveal.