[英]SQL query to delete records when the difference between two dates is greater than a certain value
I would like to delete records when the difference between SYSDATE and a TIMESTAMP (6) field of my table is greater than 10 days.当我的表的 SYSDATE 和 TIMESTAMP (6) 字段之间的差异大于 10 天时,我想删除记录。 I have created the following query:我创建了以下查询:
select (SYSDATE - myDate) as difference from myTable where difference > 10;
but i get the following error:但我收到以下错误:
00904. 00000 - "%s: invalid identifier"
am i creating the query correctly?我是否正确创建查询?
am i creating the query correctly?我是否正确创建查询?
No, you cannot refer to an alias in the SELECT
clause in the filter condition of the same statement.不,您不能在同一语句的过滤条件中SELECT
子句中的别名。
Additionally, when you subtract a TIMESTAMP
from a DATE
you will get the result as an INTERVAL
data type;此外,当您从DATE
中减去TIMESTAMP
时,您将获得INTERVAL
数据类型的结果; so you need to compare on that rather than a NUMBER
(which would be the result if you compared DATE - DATE
).所以你需要比较它而不是一个NUMBER
(如果你比较DATE - DATE
这将是结果)。
You want:你要:
SELECT SYSDATE - myDate as difference
FROM myTable
WHERE SYSDATE - myDate > INTERVAL '10' DAY;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.