{"publisher":"WESWOO","id":"subscription-due-cycles","engine":"SQLite","title":{"zh":"查看样例记录与复核查询","en":"Inspect sample records and query"},"setup_sql":"CREATE TABLE cycle(id TEXT PRIMARY KEY,contract TEXT,due INT,skipped INT);\nCREATE TABLE attempt(id TEXT PRIMARY KEY,cycle TEXT,outcome TEXT,linked_order TEXT,at INT);\nINSERT INTO cycle VALUES ('a','A',5,0),('b','B',5,0),('c','C',5,1),('d','D',30,0);\nINSERT INTO attempt VALUES ('1','a','failed',NULL,5),('2','a','success','order42',6),\n ('3','b','failed',NULL,5),('4','b','failed',NULL,6);","query_sql":"SELECT c.id,CASE WHEN COUNT(DISTINCT a.linked_order)>1 THEN 'review multiple orders'\n WHEN COUNT(DISTINCT a.linked_order)=1 THEN 'order linked' WHEN c.skipped=1 THEN 'recorded skip'\n WHEN COUNT(a.id)=0 THEN 'no attempt found' WHEN SUM(a.outcome<>'failed')=0 THEN 'failed attempts only' ELSE 'review attempt' END\nFROM cycle c LEFT JOIN attempt a ON c.id=a.cycle AND a.at<=20 WHERE due<=20 GROUP BY c.id ORDER BY c.id;","checks":[{"condition":"Review on day 20","change_sql":"","expected":[["a","order linked"],["b","failed attempts only"],["c","recorded skip"]],"observed":[["a","order linked"],["b","failed attempts only"],["c","recorded skip"]]},{"condition":"B later succeeds on day 18","change_sql":"INSERT INTO attempt VALUES ('5','b','success','order55',18);","expected":[["a","order linked"],["b","order linked"],["c","recorded skip"]],"observed":[["a","order linked"],["b","order linked"],["c","recorded skip"]]},{"condition":"B attempt history unavailable","change_sql":"DELETE FROM attempt WHERE cycle='b';","expected":[["a","order linked"],["b","no attempt found"],["c","recorded skip"]],"observed":[["a","order linked"],["b","no attempt found"],["c","recorded skip"]]},{"condition":"A has two distinct linked orders","change_sql":"INSERT INTO attempt VALUES ('6','a','success','order43',7);","expected":[["a","review multiple orders"],["b","failed attempts only"],["c","recorded skip"]],"observed":[["a","review multiple orders"],["b","failed attempts only"],["c","recorded skip"]]}]}