I have a table of sales reports (eod_cache). I’m trying to get a list of each week of sales, beginning with Monday, OR if the first date of sales is not a Monday, then adding that to the list as well. For example, if there are daily sales starting on 7/20/2011 through today, the list would be:
7/25/2011
7/20/2011
I am currently getting just Mondays, and wondering how I can add the minimum/smallest date to my list of returned dates. Here is my statement:
SELECT DISTINCT date
FROM eod_cache
WHERE DAYOFWEEK(date) = 2
ORDER BY date DESC
You can add an
ORcondition to yourDAYOFWEEKcriteria that also allows in the smallest date.In this example, I’m just using the smallest date in the table itself, though it looks like you might want to modify that query to use your permissions infrastructure, but that modification should be self-explanatory.