PostgreSQL:从间隔中掉落一秒

时间:2011-02-03 10:15:03

标签: postgresql time intervals

我的查询:

SELECT AVG(time_out - time_in) from time_table

结果:

3 days 17:21:21.062313

问题是,计算的平均值也有一秒的小数部分.062313,我不需要,所以我必须放弃它。我该怎么做?

2 个答案:

答案 0 :(得分:3)

date_trunc应该这样做:

SELECT date_trunc('second', avg(time_out - time_in))
FROM time_table

答案 1 :(得分:1)

SELECT (AVG(time_out - time_in))::INTERVAL(0) FROM time_table;

SELECT CAST(AVG(time_out - time_in) AS INTERVAL(0)) FROM time_table;