【发布时间】:2020-02-11 17:29:41
【问题描述】:
我有一个包含以下字段的邀请表:
Invitations: id, created_at, completed_at
我正在编写一个 PostgreSQL 查询,该查询按每周群组(过去 7 天)分解数据并显示平均完成时间(created_at 和 completed_at 之间的天数差异)。仅供参考,completed_at 可能为 null,表示未完成。
这是我目前所拥有的:
SELECT TRUNC(DATE_PART('day', CURRENT_DATE - i.created_at )/7) AS weeks_ago,
date(min(i.created_at)) AS "Date Start",
date(max(i.created_at)) AS "Date End",
count(DISTINCT i.id) AS "Total Num Invites",
TIMESTAMPDIFF('day', i.created_at, i.completed_at)
FROM invitations i
GROUP BY weeks_ago
ORDER BY weeks_ago ASC;
这是错误的:
ERROR: function timestampdiff(unknown, timestamp without time zone, timestamp without time zone) does not exist
LINE 5: TIMESTAMPDIFF('day', i.created_at, i.completed_at)
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
, Time: 0.085000s
我正在使用 PostgreSQL,我在这里做错了什么?
【问题讨论】:
-
我在这里做错了什么?也许调用了一个不存在的函数?
标签: sql postgresql