我希望按周显示一个月内的日期,这就是我所做的。
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
但是对于六月它显示我7月1日。我猜是因为7月1日,这是一个星期一,但我不知道如何解决这个问题。
提前谢谢
以六月为例
+------------+ | dt | +------------+ | 2013-06-01 | | 2013-06-08 | | 2013-06-15| | 2013-06-22 | | 2013-06-29 | +------------+
和2013-06-01组2013-06-01截至2013-06-07和2013-06-08组2013-06-08截至2013-06-14 ....
答案 0 :(得分:1)
考虑这个数据集......
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 |
+------------+
......像这样的黑客可能有用......
SELECT dt FROM calendar WHERE year(dt) = 2013 AND MONTH(dt) = 6 AND MOD(DAY(dt),7)=1 ;
答案 1 :(得分:0)
SELECT COUNT(table1.Id),OverWeek 从 ( 选择 *, YEAR(table1.date1)= YEAR(CURDATE()) AND MONTHNAME(table1.date1)=“六月” 来自订单 )o GROUP BY OverWeek;