sql - 如何使用 TIMESTAMPDIFF 获取 PostgreSQL 中 2 个日期之间的差异?
问题描述
我试图得到它:
SELECT * FROM "Employee" WHERE TIMESTAMPDIFF('YEAR', "BirthDate", "HireDate");
但我得到下一个错误:
ERROR: function timestampdiff(unknown, timestamp without time zone, timestamp without time zone) does not exist
LINE 1: SELECT * FROM "Employee" WHERE TIMESTAMPDIFF('YEAR', "BirthD...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
我找到了另一种方法来获得两个日期之间的差异,但在我的说明中它说我必须通过TIMESTAMPDIFF
. 有人可以帮我看哪里以及如何解决我的错误吗?
解决方案
您可以使用减号运算符
EXTRACT(DAY FROM (HireDate)-(BirthDate)) AS DateDifference
例子select date '2001-10-01' - date '2001-09-28'
推荐阅读
- python - 检查列表中是否包含某些内容
- node.js - API 端点适用于浏览器 URL,但不适用于客户端应用程序
- android - 哪个数据库提供简单的数据加密?领域 vs greenDao vs (room+saferoom) vs (sqlLite+cipher)
- django - 如何从 django 函数中发出 POST 请求以休息 api?
- python - 当我启动 django 服务器时,循环导入导致错误
- ios - iOS 中的 Stripe 集成 - 您没有提供 API 密钥?
- java - 如何为 OneToMany 连接编写单元测试(测试 Rest 端点)?
- javascript - AWS Javascript SDK 中回调函数的返回值
- android - 统一从android插件访问方法
- ios - 为什么我的物理 iPhone 没有在 xcode 中显示以测试应用程序?