表:issue 字段:
id:1
time:2012-04-01 08:15:00
count:12。。按小时统计count总数,结果如下
1 2012-04-01 8:00~9:00 134
2 2012-04-01 9:00~10:00 134
id:1
time:2012-04-01 08:15:00
count:12。。按小时统计count总数,结果如下
1 2012-04-01 8:00~9:00 134
2 2012-04-01 9:00~10:00 134
解决方案 »
- 求助,求一mysql查询表达式
- 怎样更新mysql数据库表中的索引
- 请教,一个统计问题
- 求某个列的最大值,文档里的没弄明白
- 网络时断时续,在做数据库操作时如何处理?
- xp下mysql安装到最后一步提示the service could not be started.error:0 请高手指教
- 如何通过ODBC连接MYSQL数据库?菜鸟初学!!!
- mysql怎么可以这样啊
- [提问]如何在MYSQL下建立新的数据库
- mysql InnoDB引擎主键选择问题
- mysql 隐式加锁 和手动加锁的区别
- db_lvyou_Data.MDF和db_lvyou_Log.LDF怎么在Navicat for MySQL打开
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)
from issue
group by DATE_FORMAT(time,'%Y-%m-%d %H:00')
FROM issue
group byy DATA_FORMAR(time,'%Y-%m-%d %h:00)
as 'time', sum(`result`) as 'count'
from letu group by left(time, 13);select DATE_FORMAT(time,'%Y-%m-%d %H:00'),sum(result)
from letu
group by DATE_FORMAT(time,'%Y-%m-%d %H:00')都不错·