TECHNOLOGIESTieInn Technologies

Count and total reconciliation: source against target

ETL & Data Warehouse Testing · 7 questions

Short notes

Key idea

Reconciliation computes the same measures on source and target and compares them: row counts, distinct business keys, totals of money columns, then the same per group (month, category, load run) to narrow down where they differ.

Syntax

WITH a AS (SELECT g, COUNT(*) AS n, SUM(x) AS total FROM src GROUP BY g),
     b AS (SELECT g, COUNT(*) AS n, SUM(x) AS total FROM tgt GROUP BY g)
SELECT COALESCE(a.g, b.g) AS g, a.n, b.n,
       ROUND(a.total, 2), ROUND(b.total, 2)
FROM a FULL OUTER JOIN b ON a.g = b.g
WHERE a.n IS DISTINCT FROM b.n
   OR ROUND(a.total, 2) IS DISTINCT FROM ROUND(b.total, 2);

Example

Shop: 80 vs 80 rows, but 78 distinct orders; totals ₹7,30,456.22 vs ₹7,44,671.17. Per month, only 2024-01, 02, 06 and 09 differ. Load log: run 1 read 33 customers but wrote 30, rejecting none.

Traps

  • Row counts alone: missing and duplicate rows cancel out.
  • <> across a FULL OUTER JOIN hides NULL sides; use IS DISTINCT FROM.
  • An INNER JOIN of aggregates drops one-sided groups.
  • Raw floating-point sums: round or use a tolerance.

Want the full lesson with step-by-step examples, a project and a certificate? ETL & Data Warehouse Testing course, ₹120 →

Questions

Open in Code Lab5 free questions
5 questions

    Count and total reconciliation: source against target

  1. Question 1easy

    What does this return?

    SELECT (SELECT COUNT(*) FROM dw_orders) - (SELECT COUNT(*) FROM orders);
  2. Count and total reconciliation: source against target

  3. Question 2easy

    How many different orders does the warehouse hold?

    SELECT COUNT(DISTINCT order_id) FROM dw_orders;
  4. Count and total reconciliation: source against target

  5. Question 3hard

    Return the month (YYYY-MM) of every month where the number of rows in dw_orders differs from the number of orders in orders. Use strftime(order_date, '%Y-%m') for the source month and order_month for the target.

    Tables
  6. Count and total reconciliation: source against target

  7. Question 4medium

    How many statuses have a different row count in the source and the target?

    WITH src AS (SELECT status, COUNT(*) AS n FROM orders GROUP BY status),
         tgt AS (SELECT status, COUNT(*) AS n FROM dw_orders GROUP BY status)
    SELECT COUNT(*)
    FROM src
    FULL OUTER JOIN tgt ON src.status = tgt.status
    WHERE src.n IS DISTINCT FROM tgt.n;
  8. Count and total reconciliation: source against target

  9. Question 5medium

    Source total is 730456.2200000001 and target total is 730456.22. What's the right way to compare them?

2 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.