{"publisher":"WESWOO","id":"consignment-shelf-units","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 stock(shop TEXT, sku TEXT, received INT, sold INT, sent_back INT, counted INT);\nINSERT INTO stock VALUES ('East','A',12,5,2,4),('West','A',8,2,0,6);","query_sql":"SELECT shop,received-sold-sent_back AS expected_on_shelf,\n       counted-(received-sold-sent_back) AS count_difference,sold AS units_to_settle\nFROM stock WHERE sku='A' ORDER BY shop;","checks":[{"condition":"Confirmed receipts, sales, returns and counts","change_sql":"","expected":[["East",5,-1,5],["West",6,0,2]],"observed":[["East",5,-1,5],["West",6,0,2]]},{"condition":"One more unit physically found","change_sql":"UPDATE stock SET counted=5 WHERE shop='East';","expected":[["East",5,0,5],["West",6,0,2]],"observed":[["East",5,0,5],["West",6,0,2]]},{"condition":"Missing count stays unknown","change_sql":"UPDATE stock SET counted=NULL WHERE shop='East';","expected":[["East",5,null,5],["West",6,0,2]],"observed":[["East",5,null,5],["West",6,0,2]]}]}