我有这个专栏(日期时间类型)
Begin time
===================
2015-12-04 00:00:06
2015-12-04 00:00:09
2015-12-04 00:00:10
2015-12-04 00:00:13
2015-12-04 00:00:18
2015-12-04 00:00:22
2015-12-04 00:00:33
2015-12-04 00:00:47
2015-12-04 00:01:00
2015-12-05 00:01:00
2015-12-05 00:01:07
2015-12-06 00:01:09
2015-12-06 00:01:11
2015-12-06 00:01:32
2015-12-06 00:01:34
2015-12-07 00:02:00
2015-12-07 00:02:59
如何从列中获取每分钟/每小时数据并将其分组如下:
Time | Count
00:00:00 - 00:00:59 | 8
00:01:00 - 00:01:59 | 7
00:02:00 - 00:02:59 | 2
00:03:00 - 00:03:59 | 0
...
23:59:00 - 23:59:59 | 0
我认为它与Grouping into interval of 5 minutes within a time range不同,因为我需要从每个日期获取所有数据并将其加总为1列。 例如,我的列中有两个类似的数据,具有不同的日期
Begin time
================
2015-12-05 00:01:00
2015-12-06 00:01:09
根据这些数据,我需要输出数据,如:
Time | Count
00:00:00 - 00:00:59 | 0
00:01:00 - 00:01:59 | 2
00:02:00 - 00:02:59 | 0
00:03:00 - 00:03:59 | 0
...
23:59:00 - 23:59:59 | 0
非常感谢你们所有人的帮助!
答案 0 :(得分:0)
您可以使用DATE_FORMAT
和GROUP BY
来获取该内容:
SELECT
DATE_FROMAT(col_date, '%H:%m:00 - %H:%m:59') AS `Time`,
COUNT(*) AS Count
FROM ..
GROUP BY `Time`