用于查找超过 30 天的日期记录的 Oracle SQL Where 子句
我想使用创建日期字段在(Oracle SQL)表中查找记录超过 30 天的记录.使用像 > 这样的运算符查找记录会很好,但是如果有人可以建议使用快速 SQL where 子句语句来查找超过 30 天的记录,那就太好了.请建议我使用的 Oracle 语法.
I want to find records in a (Oracle SQL) table using the creation date field where records are older than 30 days. It would be nice to find records using a operators like > but if anyone can suggest quick SQL where clause statement to find records older than 30 days that would be nice. Please suggest Oracle syntax as that is what I am using.
使用:
SELECT *
FROM YOUR_TABLE
WHERE creation_date <= TRUNC(SYSDATE) - 30
SYSDATE 返回日期 &时间;TRUNC 将日期重置为午夜,因此如果您想要 creation_date
即 30 天前,包括当前时间.
SYSDATE returns the date & time; TRUNC resets the date to being as of midnight so you can omit it if you want the creation_date
that is 30 days previous including the current time.
根据您的需要,您还可以考虑使用 ADD_MONTHS:
Depending on your needs, you could also look at using ADD_MONTHS:
SELECT *
FROM YOUR_TABLE
WHERE creation_date <= ADD_MONTHS(TRUNC(SYSDATE), -1)