runtime
32 / 88

task Join fan-out & cardinality · medium

Orders whose payments don't match

For delivered or shipped orders, return id, order_total (sum of quantity × unit_price), paid_total (sum of payments) and balance (order_total − paid_total) where paid_total differs from order_total.

what to return

Columns
idorder_totalpaid_totalbalance in this order
Rows
3 rows · any order
Watch for
Orders with no payment have paid_total 0.
Round all three amounts to 2 decimals and compare the rounded totals.
Skill
Compare totals from two child tables without fan-out. Refresher: Keep unmatched rows →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result3 rows · any order
idorder_totalpaid_totalbalance
119554510
12145045
125178183-5

all 3 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

sales_orders5 columns · 33 rows
idinteger · keyshopper_idinteger → shoppersorder_datetextstatustextdelivered_datetext
10112025-01-04delivered2025-01-08
10222025-01-06delivered2025-01-07
10312025-01-15delivered2025-01-20
10432025-01-18cancelledNULL
10542025-01-22delivered2025-01-31

showing 5 of 33 rows

order_lines4 columns · 48 rows
order_idinteger → sales_ordersitem_idinteger → catalog_itemsquantityintegerunit_pricereal
1011139
1013219.5
1024159
1035145
10310312

showing 5 of 48 rows

order_payments5 columns · 29 rows
idinteger · keyorder_idintegerpaid_attextamountrealmethodtext
11012025-01-0478card
21022025-01-0659paypal
31032025-01-1581card
41052025-01-2290card
51052025-01-2338gift_card

showing 5 of 29 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.