{"publisher":"WESWOO","id":"second-order-calendar","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 purchase(buyer TEXT, placed TEXT, id TEXT UNIQUE);\nINSERT INTO purchase VALUES ('A','2026-01-05','1'),('A','2026-04-04','2'),('A','2026-05-02','3'),\n ('B','2026-04-01','4'),('B','2026-04-22','5'),('C','2026-04-15','6');","query_sql":"WITH sequence AS (\n SELECT *, ROW_NUMBER() OVER (PARTITION BY buyer ORDER BY placed,id) AS nth FROM purchase\n) SELECT buyer,id FROM sequence WHERE nth=2 AND placed>='2026-04-01' AND placed<'2026-05-01' ORDER BY buyer;","checks":[{"condition":"Rank over full purchase history","change_sql":"","expected":[["A","2"],["B","5"]],"observed":[["A","2"],["B","5"]]},{"condition":"A has an earlier second purchase","change_sql":"INSERT INTO purchase VALUES ('A','2026-03-01','7');","expected":[["B","5"]],"observed":[["B","5"]]},{"condition":"B returns on May 1 instead","change_sql":"UPDATE purchase SET placed='2026-05-01' WHERE id='5';","expected":[["A","2"]],"observed":[["A","2"]]}]}