Problems / Inventory Reconciliation / Editorial
SUM(qty_change) GROUP BY product_id
closing_stock
opening_stock
expected_closing
discrepancy
Reconciliation queries compare two independent accounts of the same truth (book stock vs counted stock), so their failure mode is asymmetric: a bug doesn't produce wrong numbers so much as *missing alarms*. The three-valued-logic trap is the sharpest version — closing <> NULL is unknown, unknown is filtered out, and the unbalanced product looks fine. Defensive COALESCE at every optional join leg is what keeps an audit query honest.
closing <> NULL
Solve Inventory Reconciliation yourself →