日期:2014-05-16 浏览次数:20747 次
mysql> select * from issue; +----+---------------------+-------+ | id | time | count | +----+---------------------+-------+ | 1 | 2012-04-01 08:15:00 | 12 | | 2 | 2012-04-01 09:15:00 | 12 | | 3 | 2012-04-01 08:25:00 | 12 | | 4 | 2012-04-01 10:15:00 | 12 | | 5 | 2012-04-01 09:15:00 | 12 | +----+---------------------+-------+ 5 rows in set (0.00 sec) mysql> select concat(date_format(time, "%Y-%m-%d %k:00~"), hour(time)+1, ":00") as 'time', sum(`count`) as 'count' -> from issue -> group by left(time, 13); +------------------------+-------+ | time | count | +------------------------+-------+ | 2012-04-01 8:00~9:00 | 24 | | 2012-04-01 9:00~10:00 | 24 | | 2012-04-01 10:00~11:00 | 12 | +------------------------+-------+ 3 rows in set (0.00 sec)
------解决方案--------------------
恩 group by left(time, 13);
------解决方案--------------------
select DATE_FORMAT(time,'%Y-%m-%d %H:00'),sum(count)
from issue
group by DATE_FORMAT(time,'%Y-%m-%d %H:00')
------解决方案--------------------
select Date_format(time,'%Y-%M-%d %H:00'),SUM(COUNT)
FROM issue
group byy DATA_FORMAR(time,'%Y-%m-%d %h:00)