如何从sql中的不同表中获取两个不同日期之间的天数?
我需要从不同的表中估计两个不同日期之间的天数。 我曾尝试使用如何从sql中的不同表中获取两个不同日期之间的天数?,sql,postgresql,datediff,Sql,Postgresql,Datediff,我需要从不同的表中估计两个不同日期之间的天数。 我曾尝试使用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 &
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),
为什么你认为Postgres有一个
datediff()
函数?没有什么能表明这一点。