I am able to retrieve the sum/total sales for all items in a particular week using the code below.
select week(real_pur_date) as week, itemcode, sum(quantity)
from sales
where week(real_pur_date) = week(20120620)
group by itemcode;
The output is:
+------+----------+---------------+
| week | itemcode | sum(quantity) |
+------+----------+---------------+
| 25 | KB001 | 11 |
| 25 | KB002 | 2 |
| 25 | KB003 | 3 |
+------+----------+---------------+
which is what I wanted
The question is how can I query MySql to return the range of dates in week 25 back into the result table?
For example,
1. range of dates in week 24 is 10-06-2012 to 16-06-2012.
2. range of dates in week 25 is 17-06-2012 to 23-06-2012.
Thanks in advance.
I’m not a MySQL guy so I had to try to convert from SQL Server functions. But, the basic math is there. I’ll let you determine how you want to pass or calculate @YEARSTART and @YEAREND.