{"publisher":"WESWOO","id":"basket-piece-distribution","engine":"SQLite","title":{"zh":"查看样例记录与复核查询","en":"Inspect sample records and query"},"setup_sql":"CREATE TABLE line(order_id TEXT,line_id TEXT,variant TEXT,units INT,eligible INT,PRIMARY KEY(order_id,line_id));\nINSERT INTO line VALUES ('A','1','tee',2,1),('B','2','tee',1,1),('B','3','sticker',1,0),\n ('C','4','tee',1,1),('C','5','cap',1,1),('D','6','card',1,0);","query_sql":"WITH basket AS (SELECT order_id,SUM(CASE WHEN eligible THEN units ELSE 0 END) AS pieces FROM line GROUP BY order_id)\nSELECT SUM(pieces=0),SUM(pieces=1),SUM(pieces>=2) FROM basket;","checks":[{"condition":"Two tees on one line; free sticker excluded","change_sql":"","expected":[[1,1,2]],"observed":[[1,1,2]]},{"condition":"Supplier-confirmed policy counts the sticker","change_sql":"UPDATE line SET eligible=1 WHERE variant='sticker';","expected":[[1,0,3]],"observed":[[1,0,3]]},{"condition":"A originally contained just one tee","change_sql":"UPDATE line SET units=1 WHERE order_id='A';","expected":[[1,2,1]],"observed":[[1,2,1]]},{"condition":"C has two lines of the same variant","change_sql":"UPDATE line SET variant='tee' WHERE line_id='5';","expected":[[1,1,2]],"observed":[[1,1,2]]}]}