How to specify date more than 3 years ago?

1.8k views Asked by At

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

My teacher request to modify from this

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

this is what I did

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

but here come the problem , I can't use DATEADD , and I realize that my teacher put current_date - pubdate , I think he want use use other methods but I had no idea.

If using DATEADD it will come out

ORA-00904: "DATEADD": invalid identifier

2

There are 2 answers

6
mahi_0707 On BEST ANSWER

Can you the below:

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:

enter image description here

6
DiscipleMichael On

I think it's about like this.

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