{"publisher":"WESWOO","id":"gift-card-balance-gap","title":{"zh":"查看样例记录与复算 SQL","en":"Inspect the example records and SQL"},"scope":{"zh":"独立构造的运营记录。每个对照均从同一份初始数据重新开始。金额如无特别说明均为最小货币单位。","en":"Constructed operating records. Each check starts from the original setup. Monetary fields use minor currency units unless stated otherwise."},"setup_sql":"CREATE TABLE ledger(opening INT,issued INT,refund_to_card INT,redeemed INT,disabled INT,adjustment INT,closing INT);\nINSERT INTO ledger VALUES (20000,4500,0,7000,0,0,17500);","query_sql":"SELECT closing-opening AS observed_change,\n issued+refund_to_card-redeemed-disabled+adjustment AS explained_change,\n closing-(opening+issued+refund_to_card-redeemed-disabled+adjustment) AS unexplained FROM ledger;","checks":[{"condition":"Issue offsets part of redemption","change_sql":"","expected":[[-2500,-2500,0]],"observed":[[-2500,-2500,0]]},{"condition":"A different mix gives the same closing","change_sql":"UPDATE ledger SET issued=0,refund_to_card=4500;","expected":[[-2500,-2500,0]],"observed":[[-2500,-2500,0]]},{"condition":"Only redemptions documented","change_sql":"UPDATE ledger SET issued=0;","expected":[[-2500,-7000,4500]],"observed":[[-2500,-7000,4500]]}]}