← SQL Operations Cases

Independent practice · SQLite

Calculate net paid amounts

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 r AS (SELECT order_id,SUM(refund) refund FROM returns GROUP BY order_id) SELECT o.order_id,o.amount-COALESCE(r.refund,0) AS net_amount FROM orders o LEFT JOIN r ON o.order_id=r.order_id WHERE o.status='paid'

A direct join repeats the sale for each refund. Order 1 net is 90.