SQL (SQLite engine)

Reconcile a summary against raw rows

Hard120 pts~45 min
  • Reconciliation
  • HAVING
  • Data drift
Practice app · Acme Commerce DB

A real SQL database (SQLite engine) seeded with an e-commerce and HR dataset, with schema browser and query runner.

Test URL
/lab/database-testing-reconcile-a-summary-against-raw-rows

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Finance reports a mismatch; reproduce the defect and write a reconciliation query that pinpoints orders whose stored total disagrees with their lines.

Your task

  1. 1Reproduce the defect: UPDATE orders SET total = total + 10 WHERE id = 5.
  2. 2Join orders to order_items and group per order.
  3. 3Return id, total, ROUND(SUM(quantity * unit_price), 2) AS items_total and ROUND(total - SUM(quantity * unit_price), 2) AS difference.
  4. 4Keep only orders where the absolute difference exceeds 0.005.

Acceptance criteria

  • The last result set lists exactly the corrupted order with its 10.00 difference
  • The query filters groups with HAVING

Constraints

  • Every run starts from a freshly seeded database, so your script must include its own setup statements.
  • Only the last result set of your script is compared, so finish with the verification query.

SQL (SQLite engine) · Database Testing · Joins, views & aggregation