我想根据日期对这一组数据进行group by
,但23:00
到22:59
为开始时间和结束时间。
例如,对于这些数据:
2014-11-05 23:04:58.0
2014-11-05 23:23:03.0
2014-11-05 23:51:54.0
2014-11-05 23:54:29.0
2014-11-05 23:58:14.0
2014-11-06 06:13:23.0
2014-11-06 06:29:58.0
2014-11-06 06:58:27.0
2014-11-06 08:21:56.0
2014-11-06 08:24:01.0
2014-11-06 23:13:47.0
2014-11-06 23:27:55.0
2014-11-06 23:30:34.0
2014-11-06 23:40:52.0
2014-11-06 23:58:53.0
2014-11-07 06:00:37.0
2014-11-07 06:23:47.0
2014-11-07 06:28:27.0
2014-11-07 06:44:13.0
我期待的是:
Count | Date
-------------------
10 | 2014-11-06
9 | 2014-11-07
答案 0 :(得分:3)
您可以通过在日期中添加一小时来获得此聚合:
select date(timestamp + interval '1' hour) as thedate, count(*)
from table t
group by date(timestamp + interval '1' hour);
答案 1 :(得分:1)
您可以使用EXTRACT功能返回小时和组。例如:
SELECT COUNT(date), date
from tableName
group by EXTRACT(hour from Date)
有关详细信息,请参阅here