Data integrity acceptance contracts · Original fictional data · Free files and full answers
Assign one primary ingest rejection reason per row
Priority: deleted→tombstone; qty<0→negative_qty; bad total→bad_total; invalid country/currency→bad_pair; otherwise accepted. Return reason,row_count with reasons actually present, sorted reason.
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
- Priority: deleted→tombstone; qty<0→negative_qty; bad total→bad_total; invalid country/currency→bad_pair; otherwise accepted. Return reason,row_count with reasons actually present, sorted reason.
- 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 reason, row_count. Sort order follows the task. Output has 5 rows; an empty CSV field means NULL.
Source data
records
10 source rows · Download records CSV
| id INTEGER | batch TEXT | customer TEXT | email TEXT | country TEXT | currency TEXT | qty INTEGER | unit_price INTEGER | total INTEGER | deleted INTEGER |
|---|---|---|---|---|---|---|---|---|---|
| 1 | A | C1 | a@x | US | USD | 2 | 100 | 200 | 0 |
| 2 | A | C1 | a@x | US | USD | 2 | 100 | 200 | 0 |
| 3 | A | C2 | b@x | GB | GBP | 1 | 300 | 250 | 0 |
| 4 | B | C2 | b@x | GB | EUR | 1 | 300 | 300 | 0 |
| 5 | B | C3 | NULL | US | USD | 0 | 50 | 0 | 0 |
| 6 | B | C4 | US | USD | -1 | 20 | -21 | 0 | |
| 7 | C | C5 | c@x | DE | USD | -3 | 20 | 60 | 1 |
| 8 | C | C6 | d@x | US | USD | 1 | 80 | 80 | 0 |
| 9 | C | C7 | d@x | US | USD | 2 | 40 | 80 | 0 |
| 10 | C | C7 | a@x | US | USD | 2 | 40 | 80 | 0 |
country_currency
3 source rows · Download country_currency CSV
| country TEXT | currency TEXT |
|---|---|
| US | USD |
| GB | GBP |
| DE | EUR |
attributes
7 source rows · Download attributes CSV
| record_id INTEGER | name TEXT | value TEXT |
|---|---|---|
| 1 | color | red |
| 1 | size | M |
| 2 | color | red |
| 3 | color | blue |
| 4 | weight | 2 |
| 5 | color | black |
| 5 | size | S |
Field dictionary and schema
records: id INTEGER — Stable source record identifier; not a row position. batch TEXT — Literal business key or category label. Match exactly and retain NULL where present. customer TEXT — Literal business key or category label. Match exactly and retain NULL where present. email TEXT — Literal business key or category label. Match exactly and retain NULL where present. country TEXT — Literal business key or category label. Match exactly and retain NULL where present. currency TEXT — Literal business key or category label. Match exactly and retain NULL where present. qty INTEGER — Physical quantity; multiply through assembly paths when the task requires it. unit_price INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task. total INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task. deleted INTEGER — Tombstone flag:1 deleted,0 active; apply precedence before filtering. country_currency: country TEXT — Literal business key or category label. Match exactly and retain NULL where present. currency TEXT — Literal business key or category label. Match exactly and retain NULL where present. attributes: record_id INTEGER — Foreign business-record identifier; match to the named source key. name TEXT — Literal business key or category label. Match exactly and retain NULL where present. value TEXT — Measured numeric value; NULL means unobserved.
A method you can reuse
- Priority: deleted→tombstone; qty<0→negative_qty; bad total→bad_total; invalid country/currency→bad_pair; otherwise accepted. Return reason,row_count with reasons actually present, sorted reason.
- For the first output record, reason = accepted; row_count = 6.
- Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.
Watch for this wrong turn
Summing independent rule failures can exceed the source count because one row can fail several rules.
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 x AS (SELECT CASE WHEN deleted=1 THEN 'tombstone' WHEN qty<0 THEN 'negative_qty' WHEN total<>qty*unit_price THEN 'bad_total' WHEN NOT EXISTS(SELECT 1 FROM country_currency c WHERE c.country=r.country AND c.currency=r.currency) THEN 'bad_pair' ELSE 'accepted' END reason FROM records r) SELECT reason,COUNT(*) row_count FROM x GROUP BY reason ORDER BY reason;
"reason","row_count" "accepted","6" "bad_pair","1" "bad_total","1" "negative_qty","1" "tombstone","1"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects