I have a database, and I've been trying for a while, but I'm not getting the results I want. Here's a sample of what I have:
+---------+---------------------+
| 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 |
+---------+---------------------+
And this is my query:
select Ammount, Date from table;
What I want to do is group by the day AND the hours of each day, and sum it, pretty much like this:
select sum(Ammount), Date from table group by hour(day(Date));
Except it groups everything together.
SELECT SUM(Ammount), Date
FROM TABLE
GROUP BY YEAR(Date),
MONTH(Date),
DAY(Date),
HOUR(Date);
select sum(Ammount), Date from table group by month(Date), day(Date), hour(Date);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.