Basically, I want to pull data from August to May for a given set of dates. Using the between operator works as long as I do not cross the year marker (i.e. BETWEEN 8 AND 12 works — BETWEEN 8 AND 5 does not). Is there any way to pull this data? Here is the SQL Query I wrote:
SELECT count(*), MONTH(DateTime)
FROM Downloads
WHERE YEAR(DateTime) BETWEEN 2009 AND 2010 AND MONTH(DateTime) BETWEEN 8 AND 5
GROUP BY MONTH(DateTime)
ORDER BY MONTH(DateTime)"
Any help is appreciated.
Thanks,
Eric R.
Using BETWEEN with YEAR() and MONTH() is going to ruin any chance of using indexes on that column anyway. I would use:
(I used my_date because I can’t bring myself to refer to a column as DateTime) 🙂