← Sales & Refund Reconciliation

Final project · SQLite

Handoff a reconciled regional ledger

Project dataset

My saved work →
Project datasetFresh dataset challenge →Each dataset keeps its own attempts.

Your work

Active 0:00 · Paused 0s

Keep a handoff you can replay

Check your current answer, then download the output and its report. The report includes the source, answer and each check so you can review what passed and what needs work.

To replay your work, open this task with the same dataset, import your answer and check it again.

Show the reference answer
WITH clean_refunds AS (
 SELECT DISTINCT r.* FROM refunds r WHERE NOT EXISTS (
  SELECT 1 FROM refunds x WHERE x.refund_id=r.refund_id AND
  (x.order_id<>r.order_id OR x.amount<>r.amount OR x.status<>r.status OR x.booked_at<>r.booked_at)
 )
), posted AS (SELECT order_id,SUM(amount) AS refunded FROM clean_refunds WHERE status='posted' AND booked_at>='2026-09-01' AND booked_at<'2026-10-01' GROUP BY order_id), ledger AS (SELECT o.*,COALESCE(p.refunded,0) AS refunded FROM orders o LEFT JOIN posted p ON p.order_id=o.order_id WHERE o.status='paid' AND o.ordered_at>='2026-09-01' AND o.ordered_at<'2026-10-01') SELECT region,COUNT(*) AS order_count,SUM(amount) AS gross_cents,SUM(refunded) AS refund_cents,SUM(amount-refunded) AS net_cents,SUM(CASE WHEN refunded>amount THEN 1 ELSE 0 END) AS over_refunded_orders FROM ledger GROUP BY region ORDER BY region;

Reconcile paid sales to posted refunds without duplicate-key or join inflation.