Free · Guided project · SQLite · Intermediate
Replay the order feed without changing revenue
Build three linked SQL stages, test replay and late cancellations, and practise protecting the last good report in a browser simulation.
Original fictional data, eight valid and four rejected public examples. Runs on this device; no sign-in, paid service, real warehouse, scheduler or cloud progress. Supplied-case matches are guided feedback, not independent mastery.
Task and business rules
Prerequisites: SELECT, CTE, GROUP BY, event versus order grain, and ROW_NUMBER or an anti-join. Amounts are integer cents in one fictional currency.
delivery_idis a physical receipt;event_idis an immutable business event;order_idis an order. Replays can change receipt ID/time, never business payload.- Each positive
source_versionis the full replacement order state, not a delta. Greatest version wins even if old data arrives last; gaps are allowed. Do not choose by receipt or event timestamp. - One event per order/version. Different payload for the same event, a second event for an order/version, or a changed original
order_daterejects the source before SQL. - Latest paid state contributes its amount and one eligible order. Cancelled contributes zero cents and zero eligible orders on the original order date. Retain a 0/0 row for an all-cancelled date.
- Return the exact stage headers in order. Nonempty output requires text/safe integer types and exact row multiplicity; row order is irrelevant. No rounding or text-to-number coercion. Empty checks establish zero rows only.
- No tax, FX, partial refund, line item or delete semantics. Reconcile eligible latest-order cents and counts, never raw receipt amounts across replays or versions.
Complete input and expected outputs
Two paid orders on Jan 1. Selecting a snapshot retains all three queries and the last published report; rerun previews on the new input.
delivery_id TEXT, event_id TEXT, order_id TEXT, source_version INTEGER, order_date TEXT, event_time TEXT, received_at TEXT, status TEXT, amount_cents INTEGER. IDs are nonblank; dates must be real YYYY-MM-DD, timestamps real UTC YYYY-MM-DDTHH:MM:SSZ, status paid/cancelled, version positive and cents nonnegative safe integers.
Raw input — 2 physical deliveries
| delivery_id | event_id | order_id | source_version | order_date | event_time | received_at | status | amount_cents |
|---|---|---|---|---|---|---|---|---|
| D01 | E01 | O1 | 1 | 2026-01-01 | 2026-01-01T09:00:00Z | 2026-01-01T09:00:05Z | paid | 10000 |
| D02 | E02 | O2 | 1 | 2026-01-01 | 2026-01-01T10:00:00Z | 2026-01-01T10:00:05Z | paid | 20000 |
Expected accepted_events — disclosed expected rows, not a worked query
| event_id | order_id | source_version | order_date | event_time | status | amount_cents |
|---|---|---|---|---|---|---|
| E01 | O1 | 1 | 2026-01-01 | 2026-01-01T09:00:00Z | paid | 10000 |
| E02 | O2 | 1 | 2026-01-01 | 2026-01-01T10:00:00Z | paid | 20000 |
Expected current_orders — disclosed expected rows, not a worked query
| order_id | source_version | order_date | status | amount_cents |
|---|---|---|---|---|
| O1 | 1 | 2026-01-01 | paid | 10000 |
| O2 | 1 | 2026-01-01 | paid | 20000 |
Expected daily_revenue — disclosed expected rows, not a worked query
| order_date | revenue_cents | eligible_order_count |
|---|---|---|
| 2026-01-01 | 30000 | 2 |
Stage 1 — accepted events
Read raw_deliveries. Keep each immutable business event once, despite new delivery IDs and receipt times.
Stage 2 — current orders
Read your materialized accepted_events output. Keep the greatest source_version for every order; each version is a full replacement state.
Blocked: match the previous stage on this input first. A wrong or missing upstream output cannot advance.
Stage 3 — daily revenue
Read your materialized current_orders output. Sum paid current states by original order_date, keeping 0/0 dates where all orders are cancelled.
Blocked: match the previous stage on this input first. A wrong or missing upstream output cannot advance.
15-second engine-load / 3-second query budget · 20,000 SQL characters · 500 output rows / 32 columns / 64,000 output bytes · SQLite allocations limited to16MiB. Cancel terminates the worker. These small local limits are not a cloud capacity guarantee.
Run Stage 1, then use its actual output in Stage 2 and Stage 3. Previews are unpublished.
Publish a simulated report
Previews never publish automatically. Match all three stages on the same current input and query revisions, then deliberately publish. Changing input or a query invalidates affected previews and publication eligibility; it keeps the last good report.
The named failure happens before publication: retry Stage 3, then publish explicitly. Wrong SQL, rejected input, engine error, timeout, Cancel or stale replies also cannot replace the last good report/run ID.
Last successfully published report
No report published yet. Running a preview does not create one.
This report is in memory until you explicitly save on this device. Saved history is not independently verified, account-synced or a production transaction.
Help and production consequences
Hints and per-stage worked queries are optional; complete input and expected rows are available before Run.
At-least-once receipts plus a deterministic SELECT do not prove exactly-once writes. Immutable events support replay/audit at storage cost; latest-state tables speed reads but lose event history. Full recomputation suits small teaching data, while large real pipelines require bounded keyed updates, transactional publication, monitoring and rollback. Unknown source-version authority is escalation, not a guessed timestamp winner.
- SQLite SELECT — author reviewed7 November2026.
- SQLite Window Functions — author reviewed7 November2026.
- SQLite Expressions / CASE — author reviewed7 November2026.
Device-only drafts and recovery
Three separate queries, source selection, assistance state and last published snapshot. No cloud/account persistence.
Loading this device's saved copy…