开发者

SQL query - group by timespan in MySQL

I have a table containing the following details:

date_info   info
2009-06-23  1
2009-06-24  2
2009-06-25  20
2009-06-26开发者_Go百科  14
2009-06-27  17
2009-06-28  5
2009-06-29  10
2009-06-30  2
etc.

I would like to group the info coloumn by occurrences per week and month, like so:

2009-06-01_2009-06-07 XXX
2009-06-08_2009-06-14 XXX

Grouping by a calendaric week would be ideal.

Ideas?


By the time I wrote the question, I figured out the solution: using WEEKOFYEAR:

SELECT WEEKOFYEAR(date_info) as MaWeek, SUM(info) from table1 GROUP BY MaWeek
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜