0

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

4

2 回答 2

2

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)
于 2015-06-21T13:18:57.673 回答
0

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

于 2015-06-21T13:50:14.713 回答