【发布时间】:2021-08-10 06:30:25
【问题描述】:
我需要估计来自不同表格的 2 个不同日期之间的天数。
我曾尝试使用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()功能? in the manual 没有任何建议。
标签: sql postgresql datediff