← Sales & Refund Reconciliation My saved work →
Independent practice · SQLite
Reconcile one company total
Practice dataset
Your work
Active 0:00 · Paused 0sKeep 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 COUNT(*) AS order_count,SUM(amount) AS gross_cents,SUM(refunded) AS refund_cents,SUM(amount-refunded) AS net_cents FROM ledger
Company totals are computed from one row per sale; raw joins make gross too large.