我有一张表格如下:
过期的产品是生产超过1年的产品。如何列出已过期的所有产品&连同他们的失效日期?PRODUCT(P_CODE,DESCRIPTION,PRODUCTION_DATE)
答案 0 :(得分:5)
create table PRODUCT(P_CODE number, DESCRIPTION varchar2(200), PRODUCTION_DATE date);
insert into product values(1,'XXX',to_date('12-03-2013','dd-mm-yyyy'));
insert into product values(2,'YYY',to_date('13-03-2012','dd-mm-yyyy'));
insert into product values(3,'ZZZ',to_date('12-08-2012','dd-mm-yyyy'));
insert into product values(4,'AAA',to_date('16-08-2013','dd-mm-yyyy'));
select p_code
,description
,production_date
,add_months(production_date,12) expire_date
from product
where production_date<add_months(sysdate,-12)
答案 1 :(得分:4)
SELECT P_CODE,PRODUCTION_DATE
FROM PRODUCT
WHERE PRODUCTION_DATE >= NOW() - INTERVAL 12 MONTH
答案 2 :(得分:0)
我不知道它是如何在oracle中完成的,但在MS SQL中它是:
SELECT P_CODE, DESCRIPTION, PRODUCTION_DATE
FROM PRODUCT
WHERE PRODUCTION_DATE < DATEADD(yy, -1, GETUTCDATE())
答案 3 :(得分:0)
SELECT *
FROM PRODUCT
WHERE DATEDIFF(YEAR,CURDATE(),DATE_ADD(PRODUCTION_DATE, INTERVAL 1 YEAR)) > 1
这是一个摇摆不定但THIS LINK应该让你到达你想去的地方