Versioned facts and temporal truth · Original fictional data · Free files and full answers
Value facts using one authoritative temporal version
At cutoff15 choose latest recorded valid version per fact, suppress tombstones and retain unmatched facts asNULL unit_value and extended_value. Return fact_id,unit_value,extended_value=amount*value sorted fact_id.
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
- At cutoff15 choose latest recorded valid version per fact, suppress tombstones and retain unmatched facts asNULL unit_value and extended_value. Return fact_id,unit_value,extended_value=amount*value sorted fact_id.
- 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 fact_id, unit_value, extended_value. Sort order follows the task. Output has 5 rows; an empty CSV field means NULL.
Source data
versions
9 source rows · Download versions CSV
| id INTEGER | entity TEXT | valid_from INTEGER | valid_to INTEGER | recorded INTEGER | value INTEGER | deleted INTEGER |
|---|---|---|---|---|---|---|
| 1 | A | 0 | 10 | 0 | 100 | 0 |
| 2 | A | 10 | 20 | 8 | 120 | 0 |
| 3 | A | 0 | 10 | 12 | 110 | 0 |
| 4 | B | 0 | 8 | 0 | 50 | 0 |
| 5 | B | 10 | 20 | 5 | 70 | 0 |
| 6 | C | 0 | 20 | 0 | 80 | 0 |
| 7 | C | 5 | 15 | 9 | 90 | 0 |
| 8 | D | 0 | 20 | 0 | 40 | 0 |
| 9 | D | 0 | 20 | 10 | NULL | 1 |
facts
5 source rows · Download facts CSV
| id INTEGER | entity TEXT | day INTEGER | amount INTEGER |
|---|---|---|---|
| 1 | A | 5 | 2 |
| 2 | A | 12 | 3 |
| 3 | B | 9 | 1 |
| 4 | C | 10 | 4 |
| 5 | D | 4 | 2 |
Field dictionary and schema
versions: id INTEGER — Stable source record identifier; not a row position. entity TEXT — Literal business key or category label. Match exactly and retain NULL where present. valid_from INTEGER — Inclusive valid-time start day. valid_to INTEGER — Exclusive valid-time end day. recorded INTEGER — Transaction-time day index when this version became known. value INTEGER — Measured numeric value; NULL means unobserved. deleted INTEGER — Tombstone flag:1 deleted,0 active; apply precedence before filtering. facts: id INTEGER — Stable source record identifier; not a row position. entity TEXT — Literal business key or category label. Match exactly and retain NULL where present. day INTEGER — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics. amount INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
A method you can reuse
- At cutoff15 choose latest recorded valid version per fact, suppress tombstones and retain unmatched facts asNULL unit_value and extended_value. Return fact_id,unit_value,extended_value=amount*value sorted fact_id.
- For the first output record, fact_id = 1; unit_value = 110; extended_value = 220.
- Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.
Watch for this wrong turn
Joining every matching version multiplies fact amounts and leaks superseded values into the report.
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
SELECT f.id fact_id,(SELECT CASE WHEN deleted=0 THEN value END FROM versions v WHERE v.entity=f.entity AND f.day>=v.valid_from AND f.day<v.valid_to AND recorded<=15 ORDER BY recorded DESC,id DESC LIMIT 1) unit_value,f.amount*(SELECT CASE WHEN deleted=0 THEN value END FROM versions v WHERE v.entity=f.entity AND f.day>=v.valid_from AND f.day<v.valid_to AND recorded<=15 ORDER BY recorded DESC,id DESC LIMIT 1) extended_value FROM facts f ORDER BY f.id;
"fact_id","unit_value","extended_value" "1","110","220" "2","120","360" "3",, "4","90","360" "5",,Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects