如何指定超过 3 年前的日期?

How to specify date more than 3 years ago?

Display details of book published more then 3 years ago with sales of less than 10000 copies

老师要求修改

Select title_id , title , pubdate , current_date-pubdate, ytd_sales
from titles;

这就是我所做的

Select title_id , title , pubdate , current_date-pubdate, ytd_sales
from titles
where ytd_sales > 10 000;

但问题来了,我不能使用 DATEADD,我意识到我的老师放了 current_date - pubdate,我想他想使用其他方法,但我不知道。

如果使用 DATEADD 它会出来

ORA-00904: "DATEADD": invalid identifier

我觉得大概是这样。

Select title_id , title , pubdate , current_date-pubdate, ytd_sales
from titles
where ytd_sales > 10 000;
AND pubdate < add_months(sysdate, -36)

你能做到以下几点吗:

alter SESSION set NLS_DATE_FORMAT = 'MM-DD-YYYY HH24:MI:SS' ;

--select * from nls_session_parameters where parameter = 'NLS_DATE_FORMAT';

create table TITLES( title_id number(10), title  varchar2(20), pubdate date, ytd_sales number(10));

insert into TITLES values(101,'ABC',TO_DATE('07-13-2011','MM-DD-YYYY'),20000);    
insert into TITLES values(102,'DEF',TO_DATE('07-13-2014','MM-DD-YYYY'),90000);    
commit;

Select title_id , title , pubdate , round( (trunc(sysdate)-pubdate) /365)  years, ytd_sales
from TITLES
where ytd_sales > 10000
and  round( (trunc(sysdate)-pubdate) /365) > 3 --this will check for the pub date > 3 years
;

OUTPUT: