{"publisher":"WESWOO","id":"rejected-transfer-correction","engine":"SQLite","title":{"zh":"查看样例记录与复核查询","en":"Inspect sample records and query"},"setup_sql":"-- Compare requested corrections with the physical disposition of the original shipment.\nCREATE TABLE receipt(shipped INT,accepted INT,rejected INT,not_sent INT,physical_good INT,physical_missing INT,physical_origin INT);\nINSERT INTO receipt VALUES(8,0,8,0,6,2,0);","query_sql":"SELECT CASE WHEN physical_good IS NULL OR physical_missing IS NULL OR physical_origin IS NULL\n OR physical_good+physical_missing+physical_origin<>shipped OR accepted+rejected+not_sent<>shipped THEN 'hold'\n ELSE 'reconciled' END AS status,\n CASE WHEN physical_good+physical_missing+physical_origin=shipped AND accepted+rejected+not_sent=shipped THEN physical_good-accepted END AS accept_delta,\n CASE WHEN physical_good+physical_missing+physical_origin=shipped AND accepted+rejected+not_sent=shipped THEN physical_origin-not_sent END AS cancel_delta\nFROM receipt;","checks":[{"condition":"6 physically good, 2 lost, all 8 accidentally rejected","change_sql":"","expected":[["reconciled",6,0]],"observed":[["reconciled",6,0]]},{"condition":"Shipment already corrected; run again","change_sql":"UPDATE receipt SET accepted=6,rejected=2;","expected":[["reconciled",0,0]],"observed":[["reconciled",0,0]]},{"condition":"Two never left origin","change_sql":"UPDATE receipt SET physical_missing=0,physical_origin=2;","expected":[["reconciled",6,2]],"observed":[["reconciled",6,2]]},{"condition":"Uncounted destination stock","change_sql":"UPDATE receipt SET physical_good=NULL;","expected":[["hold",null,null]],"observed":[["hold",null,null]]}]}