I have an SQL statement that selects a range of values and then groups them by year/month/day. This appears to work fine.
What is really confusing, is that if I run this SQL on the next day, the result numbers change. I think overall, the numbers are correct, but they change by one or two when run on different days.
eg.
select Date_format(startDate, "%Y-%m-%d") as Date, count(*) as Online
from
`promotion` p, `subscription` s
where
p.`uid` = s.`uid` and
s.`productId` = "groupproduct"
startDate < now()
GROUP BY YEAR(startDate), MONTH(startDate), DAYOFMONTH(startDate);
Results on Day X
2012-12-25 265
2012-12-26 264
2012-12-27 232
2012-12-28 187
2012-12-29 171
2012-12-30 8935
2012-12-31 3117
Results on Day X+1
2012-12-25 265
2012-12-26 264
2012-12-27 231
2012-12-28 187
2012-12-29 171
2012-12-30 8933
2012-12-31 3114
Notice how on 27.12.2012 and 30.12.2012 the result are off by one. What am I missing? I assume there is a counting error using the Group by functions, but I don't know what.
NB. This SQL is run by a cronjob each day in the morning. Not by hand, so I don't think user error is to blame here (except in the creation of the statement).
EDIT: Sorry, there was a mistake in the printed SQL (I changed it slightly for the public). It should be startDate every where. The issue still stands.