{"publisher":"WESWOO","id":"warehouse-sku-crosswalk","title":{"zh":"查看样例与复核查询","en":"View the records and verification query"},"setup_sql":"CREATE TABLE map(location TEXT,external TEXT,variant TEXT,PRIMARY KEY(location,external,variant));\nINSERT INTO map VALUES ('East','A7','v12'),('West','B9','v12'),('West','A7','v45');\nCREATE TABLE feed(location TEXT,external TEXT,on_hand INT,PRIMARY KEY(location,external));\nINSERT INTO feed VALUES ('East','A7',6),('West','B9',9),('West','NEW',4);","query_sql":"SELECT f.location,f.external,f.on_hand,CASE WHEN COUNT(m.variant)=1 THEN MIN(m.variant) END AS target,\n CASE COUNT(m.variant) WHEN 0 THEN 'missing' WHEN 1 THEN 'matched' ELSE 'ambiguous' END AS review\nFROM feed f LEFT JOIN map m ON m.location=f.location AND m.external=f.external\nGROUP BY f.location,f.external,f.on_hand ORDER BY f.location,f.external;","checks":[{"condition":"Two local codes for one variant; third code missing","change_sql":"","expected":[["East","A7",6,"v12","matched"],["West","B9",9,"v12","matched"],["West","NEW",4,null,"missing"]],"observed":[["East","A7",6,"v12","matched"],["West","B9",9,"v12","matched"],["West","NEW",4,null,"missing"]]},{"condition":"West also uses A7 for a different variant","change_sql":"INSERT INTO feed VALUES ('West','A7',3);","expected":[["East","A7",6,"v12","matched"],["West","A7",3,"v45","matched"],["West","B9",9,"v12","matched"],["West","NEW",4,null,"missing"]],"observed":[["East","A7",6,"v12","matched"],["West","A7",3,"v45","matched"],["West","B9",9,"v12","matched"],["West","NEW",4,null,"missing"]]},{"condition":"One incoming key has two mappings","change_sql":"INSERT INTO map VALUES ('East','A7','v99');","expected":[["East","A7",6,null,"ambiguous"],["West","B9",9,"v12","matched"],["West","NEW",4,null,"missing"]],"observed":[["East","A7",6,null,"ambiguous"],["West","B9",9,"v12","matched"],["West","NEW",4,null,"missing"]]}]}