0

I want to display the days in a month grouping by week, that's what I did.

select date(subdate(table1.date1, interval (dayofweek(table1.date1)-2)day))  as OverWeek,count(table1.Id)
from table1
where YEAR(table1.date1 ) = YEAR(CURDATE())
AND MONTHNAME(table1.date1) = "June"
GROUP BY OverWeek

But for June it shows me 1 July . I guess' cause on 1 July , it's a Monday, but I do not know how to solve this porblème.

Thank you in advance

For June for exemple

+------------+
| dt         |
+------------+
| 2013-06-01 |
| 2013-06-08 |
| 2013-06-15|
| 2013-06-22 |
| 2013-06-29 |
+------------+

and 2013-06-01 group 2013-06-01 up to 2013-06-07 and 2013-06-08 group 2013-06-08 up to 2013-06-14 ....

4

2 回答 2

2

Considering this data set...

SELECT * FROM calendar WHERE year(dt) = 2013 AND MONTH(dt) = 6;
+------------+
| dt         |
+------------+
| 2013-06-01 |
| 2013-06-02 |
| 2013-06-03 |
| 2013-06-04 |
| 2013-06-05 |
| 2013-06-06 |
| 2013-06-07 |
| 2013-06-08 |
| 2013-06-09 |
| 2013-06-10 |
| 2013-06-11 |
| 2013-06-12 |
| 2013-06-13 |
| 2013-06-14 |
| 2013-06-15 |
| 2013-06-16 |
| 2013-06-17 |
| 2013-06-18 |
| 2013-06-19 |
| 2013-06-20 |
| 2013-06-21 |
| 2013-06-22 |
| 2013-06-23 |
| 2013-06-24 |
| 2013-06-25 |
| 2013-06-26 |
| 2013-06-27 |
| 2013-06-28 |
| 2013-06-29 |
| 2013-06-30 |
+------------+

...a hack like this might work...

SELECT dt FROM calendar WHERE year(dt) = 2013 AND MONTH(dt) = 6 AND MOD(DAY(dt),7)=1 ;
于 2013-07-02T09:35:11.643 回答
0

SELECT COUNT(table1.Id), OverWeek FROM ( SELECT *, where YEAR(table1.date1 ) = YEAR(CURDATE()) AND MONTHNAME(table1.date1) = "June" FROM Orders ) o GROUP BY OverWeek;

于 2013-07-02T09:43:31.057 回答