It’s one line of SQL… If you’re talking about the whole sugar tracking app, he admitted a few weeks ago that it won’t be of any use to Type 1 diabetics as a food log is out of the question
The code from Dave didn’t give me the results I expected, but this code did:
SELECT myDate,
myField,
(SELECT AVG(myField) FROM myTable b
WHERE myDate BETWEEN date(a.myDate, '-30 days') AND date(a.myDate)) AS myAvg
From myTable a
Some notes:
using ‘-30 days’ will give you an average of 31 days
the least you could have is an average of 2 days (using ‘-1 day’)
sorry if I made a mistake changing my real values to generic ones
Alberto… you may have needed to change it as you did, if your date field is not in YYYY-MM-DD format, then the DATE() function compensates for that (to a point)
Thank you Dave, as you know I’m new to programming.
As far as I can tell, my sqlite database was created with Fecha as DATE and the values are in YYYY-MM-DD format. I will keep looking as why your code didn’t work for me.
which is quite complex… it has a database with 8 tables, and 12 views, 16 screens, it creates user customized PDF reports along with configurable graphs, so it is way more that a “code challenge”