{"publisher":"WESWOO","id":"basket-pair-baseline","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 line_item(order_id INT,sku TEXT);\nINSERT INTO line_item VALUES (1,'Boot'),(1,'Sock'),(2,'Boot'),(2,'Sock'),(3,'Boot'),(4,'Boot'),\n (5,'Sock'),(6,'Sock'),(7,'Sock'),(8,'Sock');","query_sql":"WITH basket AS (SELECT order_id,MAX(sku='Boot') boot,MAX(sku='Sock') sock FROM line_item GROUP BY order_id)\nSELECT COUNT(*) AS orders,SUM(boot) AS boot_orders,SUM(sock) AS sock_orders,SUM(boot*sock) AS both,\n ROUND((1.0*SUM(boot*sock)/NULLIF(SUM(boot),0))/(1.0*SUM(sock)/COUNT(*)),3) AS lift FROM basket;","checks":[{"condition":"Compare attach rate with overall sock demand","change_sql":"","expected":[[8,4,6,2,0.667]],"observed":[[8,4,6,2,0.667]]},{"condition":"Three more sock lines on the same order","change_sql":"INSERT INTO line_item VALUES (1,'Sock'),(1,'Sock'),(1,'Sock');","expected":[[8,4,6,2,0.667]],"observed":[[8,4,6,2,0.667]]},{"condition":"All four boot orders include socks","change_sql":"INSERT INTO line_item VALUES (3,'Sock'),(4,'Sock');","expected":[[8,4,8,4,1]],"observed":[[8,4,8,4,1]]}]}