{"publisher":"WESWOO","id":"older-stock-remaining","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 counts(old_lot INT,new_lot INT,sold_since INT);\nINSERT INTO counts VALUES (10,6,8);","query_sql":"SELECT old_lot+new_lot-sold_since AS remaining,MAX(0,old_lot-sold_since) AS old_min,\n MIN(old_lot,old_lot+new_lot-sold_since) AS old_max FROM counts;","checks":[{"condition":"Sales carry no lot ID","change_sql":"","expected":[[8,2,8]],"observed":[[8,2,8]]},{"condition":"No newer receipt","change_sql":"UPDATE counts SET new_lot=0;","expected":[[2,2,2]],"observed":[[2,2,2]]},{"condition":"No sales after either receipt","change_sql":"UPDATE counts SET sold_since=0;","expected":[[16,10,10]],"observed":[[16,10,10]]}]}