本文介绍了如何在PostgreSQL中获取两个日期之间的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Postgres中获取两个日期之间的平均日期:
I'd like to get the average date between two dates in Postgres:
在SqlServer中,通过以下简单查询即可完成操作:
In SqlServer is done with this simple query:
SELECT DateAdd(ms, DateDiff(ms, date_begin, date_end)/2, date_begin)例如:
SELECT DateAdd(ms, DateDiff(ms, getdate(), dateadd(d, 1, getdate()))/2, getdate())现在,我想在postgres中进行相同的查询。 我尝试使用类似的
Now I'd like to make the same query in postgres. I try with something like
SELECT current_timestamp + ((SELECT ((DATE_PART('day', (current_timestamp + INTERVAL '1 day')::timestamp - current_timestamp::timestamp) * 24 + DATE_PART('hour', (current_timestamp + INTERVAL '1 day')::timestamp - current_timestamp::timestamp)) * 60 + DATE_PART('minute', (current_timestamp + INTERVAL '1 day')::timestamp - current_timestamp::timestamp)) * 60 + DATE_PART('second', (current_timestamp + INTERVAL '1 day')::timestamp - current_timestamp::timestamp)||'second')::interval不起作用。
在Postgres中,有没有更简单的方法来进行此简单操作?
Is there a simpler way to make this simple operation in Postgres?
推荐答案怎么样:
select date_begin + (date_end - date_begin)/2更多推荐
如何在PostgreSQL中获取两个日期之间的平均值
发布评论