你的数据说除了梨+橙之外的其他人今天到期,所以假设你想排除今天到期并包括那些在 2 个月内到期的人:
SQL> select food, manufacturedate, add_months(manufacturedate,12) expiry_date from product where add_months(manufacturedate, 12) <= add_months(trunc(sysdate), 2) and add_months(manufacturedate, 12) > trunc(sysdate);
FOOD MANUFACTU EXPIRY_DA
--------------- --------- ---------
orange 12-JAN-12 12-JAN-13
pear 12-JAN-12 12-JAN-13
或更便于索引的放置方式(删除列侧的功能):
SQL> select food, manufacturedate, add_months(manufacturedate,12) expiry_date from product where manufacturedate <= add_months(trunc(sysdate), -10) and manufacturedate > add_months(trunc(sysdate), -12);
FOOD MANUFACTU EXPIRY_DA
--------------- --------- ---------
orange 12-JAN-12 12-JAN-13
pear 12-JAN-12 12-JAN-13