I am working with SQLite.
Suppose I have a table sales
with two columns, date
and count
, to keep track of how many glasses of lemo
I think you need something like this:
SELECT sum(count) / ((strftime('%s','2010-01-10')-strftime('%s','2010-01-04')+86400)/86400)
FROM sales
WHERE date IS BETWEEN '2010-01-04' AND '2010-01-10';
The query calculates the exact number of days by taking the seconds between the given dates
and dividing with 86400 (= 24*3600) secs.
For example
SELECT (strftime('%s','2010-03-01')-strftime('%s','2010-01-01') + 86400) / 86400
outputs 60
which is the correct value.
Check out SQLite's Date And Time Functions.