postgre如何从sql中的不同表中获取两个不同日期之间的天数



我需要估计不同表中两个不同日期之间的天数。我尝试过使用datediff函数,但没有成功。

这是我尝试的查询:

select 
t1."group",
datediff(t2.start_date, t1.event_date),
count(distinct t1.employee_id)
from t1 join t2 on t1.project_id = t2.id
where true
and t1.cummulative_manhour > 0
and t1.company_id in ('a', 'b')
and t1.event_date = '2021-05-17'
and t1.project_id = '2900'
group by 
t1."group",
t2.start_date,
t1.event_date

错误信息显示:

SQL Error [42883]: ERROR: function datediff(date, date) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 29

我使用的数据库是postgresql。

我应该如何编写查询才能获得预期的天数?

提前谢谢。

正如错误消息所示,Postgres不支持datediff()。相反,它只是使用-:

(t2.start_date - t1.event_date),

最新更新