{"publisher":"WESWOO","id":"shipping-label-net-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 shipment(collected INT, refunded_to_buyer INT);\nCREATE TABLE bill(type TEXT,amount INT);\nINSERT INTO shipment VALUES (400,0);\nINSERT INTO bill VALUES ('label',800),('void credit',-800),('replacement label',750);","query_sql":"SELECT collected-refunded_to_buyer AS net_shipping_collected,(SELECT SUM(amount) FROM bill) AS postage,\n collected-refunded_to_buyer-(SELECT SUM(amount) FROM bill) AS shipping_balance FROM shipment;","checks":[{"condition":"Original label credited before replacement","change_sql":"","expected":[[400,750,-350]],"observed":[[400,750,-350]]},{"condition":"Carrier surcharge on final bill","change_sql":"INSERT INTO bill VALUES ('surcharge',125);","expected":[[400,875,-475]],"observed":[[400,875,-475]]},{"condition":"Customer shipping refunded","change_sql":"UPDATE shipment SET refunded_to_buyer=400;","expected":[[0,750,-750]],"observed":[[0,750,-750]]}]}