← Sales & Refund Reconciliation

Independent practice · SQLite

List canonical orphan refunds

Practice dataset

My saved work →

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)
 )
) SELECT r.refund_id,r.order_id FROM clean_refunds r LEFT JOIN orders o ON o.order_id=r.order_id WHERE o.order_id IS NULL ORDER BY r.refund_id

An orphan needs follow-up; inventing an order would corrupt the ledger.