← SQL workplace practice

Data integrity acceptance contracts · Original fictional data · Free files and full answers

Quantify reference validity within each import batch

Return batch,source_rows,valid_currency_pairs,invalid_currency_pairs using the exact country/currency pair rule, retaining duplicate source rows because this is ingest coverage. Sort batch.

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

  1. Return batch,source_rows,valid_currency_pairs,invalid_currency_pairs using the exact country/currency pair rule, retaining duplicate source rows because this is ingest coverage. Sort batch.
  2. 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.
  3. 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 batch, source_rows, valid_currency_pairs, invalid_currency_pairs. Sort order follows the task. Output has 3 rows; an empty CSV field means NULL.

Source data

records

10 source rows · Download records CSV

id INTEGERbatch TEXTcustomer TEXTemail TEXTcountry TEXTcurrency TEXTqty INTEGERunit_price INTEGERtotal INTEGERdeleted INTEGER
1AC1a@xUSUSD21002000
2AC1a@xUSUSD21002000
3AC2b@xGBGBP13002500
4BC2b@xGBEUR13003000
5BC3NULLUSUSD05000
6BC4USUSD-120-210
7CC5c@xDEUSD-320601
8CC6d@xUSUSD180800
9CC7d@xUSUSD240800
10CC7a@xUSUSD240800

country_currency

3 source rows · Download country_currency CSV

country TEXTcurrency TEXT
USUSD
GBGBP
DEEUR

attributes

7 source rows · Download attributes CSV

record_id INTEGERname TEXTvalue TEXT
1colorred
1sizeM
2colorred
3colorblue
4weight2
5colorblack
5sizeS
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.

Download complete SQLite setup

A method you can reuse

  1. Return batch,source_rows,valid_currency_pairs,invalid_currency_pairs using the exact country/currency pair rule, retaining duplicate source rows because this is ingest coverage. Sort batch.
  2. For the first output record, batch = A; source_rows = 3; valid_currency_pairs = 3; invalid_currency_pairs = 0.
  3. Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

Watch for this wrong turn

Deduplicating before an ingestion-quality report changes the source row denominator.

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 batch,COUNT(*) source_rows,SUM(EXISTS(SELECT 1 FROM country_currency c WHERE c.country=r.country AND c.currency=r.currency)) valid_currency_pairs,SUM(NOT EXISTS(SELECT 1 FROM country_currency c WHERE c.country=r.country AND c.currency=r.currency)) invalid_currency_pairs FROM records r GROUP BY batch ORDER BY batch;
"batch","source_rows","valid_currency_pairs","invalid_currency_pairs"
"A","3","3","0"
"B","3","2","1"
"C","4","3","1"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects