Skip to content
Lohith.

Engineering Playground · SQL

Data Quality Detective

Four incidents from a shipping and payments data platform. Investigate each one with SQL: find the duplicate loads, the orders that never shipped, the settlements that don't match, then build the report finance actually needs.

Loading the SQLite engine…

Case 1 · Payment reconciliation

The double-charged customers

Support tickets say some customers were charged twice. The processor feed was replayed during an outage, and the transactions table has no unique key, so the same transaction may have been loaded more than once.

Your task

Find every txn_id that appears in transactions more than once.

Your result must include: txn_id (a count of copies is a nice extra).

  • GROUP BY
  • COUNT
  • HAVING

Use hints or the solution whenever they help. Your summary just notes which you used.

Schema explorer

Synthetic demonstration data. Not real company, customer or payment records.

Dataset A · Shipping operations

  • warehouses5 rows

    Distribution centres that fulfil orders.

    • warehouse_idTEXT· primary key
    • nameTEXT
    • cityTEXT
    • stateTEXT
  • orders36 rows

    Customer orders, one row per order.

    • order_idTEXT· primary key
    • customer_idTEXT
    • warehouse_idTEXT· → warehouses
    • order_dateTEXT· YYYY-MM-DD
    • total_amountREAL
  • shipments32 rows

    Carrier shipments. An order can be split across shipments.

    • shipment_idTEXT· primary key
    • order_idTEXT· → orders
    • carrierTEXT
    • statusTEXT· delivered, in_transit or NULL
    • shipped_dateTEXT
    • delivered_dateTEXT

Dataset B · Payment reconciliation

  • merchants6 rows

    Merchants that accept card payments.

    • merchant_idTEXT· primary key
    • nameTEXT
    • categoryTEXT
    • countryTEXT
  • transactions45 rows

    Card transactions as ingested from the processor feed (no unique key).

    • txn_idTEXT
    • merchant_idTEXT· → merchants
    • amountREAL· expected amount
    • currencyTEXT
    • txn_dateTEXT· YYYY-MM-DD
    • statusTEXT· captured or declined
  • settlements36 rows

    Funds the acquirer actually settled to each merchant.

    • settlement_idTEXT· primary key
    • txn_idTEXT· → transactions
    • merchant_idTEXT· → merchants
    • settled_amountREAL
    • settlement_dateTEXT· YYYY-MM-DD

SQL editor · SQLite

Loading engine

Read-only SQLite. One SELECT statement at a time. Ctrl + Enter (⌘ + Enter on Mac) runs the query.

Run a query to see its results here.