我有一个数据库,我已经尝试了一段时间,但我没有得到我想要的结果。以下是我的样本:
+---------+---------------------+
| Ammount | Date |
+---------+---------------------+
| 1 | 2015-08-25 14:07:00 |
| 1 | 2015-08-25 14:12:00 |
| 1 | 2015-08-25 15:17:00 |
| 2 | 2015-08-25 15:22:00 |
| 1 | 2015-08-25 14:27:00 |
| 6 | 2015-08-25 14:32:00 |
| 1 | 2015-08-26 14:37:00 |
| 5 | 2015-08-26 14:42:00 |
| 1 | 2015-08-26 16:47:00 |
| 2 | 2015-08-26 16:52:00 |
+---------+---------------------+
这是我的疑问:
select Ammount, Date from table;
我想要做的是按天和每天的小时进行分组,然后总结一下,就像这样:
select sum(Ammount), Date from table group by hour(day(Date));
除了将所有内容组合在一起外。
答案 0 :(得分:1)
SELECT SUM(Ammount), Date
FROM TABLE
GROUP BY YEAR(Date),
MONTH(Date),
DAY(Date),
HOUR(Date);
答案 1 :(得分:0)
select sum(Ammount), Date from table group by month(Date), day(Date), hour(Date);