开发者

SQL query - group by timespan in MySQL

开发者 https://www.devze.com 2022-12-15 02:03 出处:网络
I have a table containing the following details: date_infoinfo 2009-06-231 2009-06-242 2009-06-2520 2009-06-26开发者_Go百科14

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

精彩评论

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