【发布时间】:2012-08-23 08:22:06
【问题描述】:
可能重复:
What is the fastest way to truncate timestamps to 5 minutes in Postgres?
Postgresql SQL GROUP BY time interval with arbitrary accuracy (down to milli seconds)
我想在 PostgreSQL 中每隔 5 分钟聚合一次数据。如果我使用date_trunc() 函数,我可以按每小时、每月、每天、每周等时间间隔聚合数据,但不能像 5 分钟或 5 天这样的特定时间间隔聚合数据。
select date_trunc('hour', date1), count(*) from table1 group by 1;
我们如何在 PostgreSQL 中实现这一点?
【问题讨论】:
-
你问的是stackoverflow.com/questions/7299342/…之类的东西吗?
-
您想要每 5 分钟的值(即使时隙没有数据),还是只跳过没有数据的间隔?
-
值得一提的是你的Pg版本;它会影响人们在写答案时可用的功能。
标签: sql postgresql datetime aggregate-functions