This can be done in a single query, but using VIEW
will become much easier:
-- Groups (without sequencial):
CREATE VIEW Grp0 AS SELECT DISTINCT STRFTIME('%W', Date) AS Week FROM MedicalRecords WHERE Date BETWEEN DATETIME('NOW', '-1 month') AND DATETIME('now', 'localtime');
-- Groups (with sequencial):
CREATE VIEW Grp AS SELECT (SELECT COUNT() FROM Grp0 AS _ WHERE Week<=Grp0.Week), Week FROM Grp0;
-- Query:
SELECT Week, (SELECT AVG(bmi) FROM MedicalRecords WHERE STRFTIME('%W', Date) = Week)) FROM Grp;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…