Sql 如何指定3年以上的日期?
展示3年前出版的书的详细信息,销量不到10000册 我的老师要求修改这个Sql 如何指定3年以上的日期?,sql,database,oracle,date-difference,Sql,Database,Oracle,Date Difference,展示3年前出版的书的详细信息,销量不到10000册 我的老师要求修改这个 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; 但是问题来了,我不能使用D
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,我意识到我的老师把当前的日期-pubdate放在了一起,我想他想使用其他方法,但我不知道
如果使用DATEADD,它将显示出来
ORA-00904:日期添加:无效标识符
我想是这样的
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
;
输出:
现在你看到了一个问题是如何格式化的——请你以后也这样做。谢谢。提示:添加月份。但是我如何在其中使用curent\u date-pubdate呢?我还不清楚,但我需要一年?或者,它应该是“加年”?可能是的复制品,只要确保在任何作业中使用它之前,您完全理解该函数,以及它是如何使用的。它对完成作业没有任何帮助,但无法理解作业的工作原理。SQL>从标题3中选择标题id、标题、发布日期、当前日期-pubdate、当前日期-pubdate、当前日期-pubdate 2,其中当前日期-pubdate