我要查EMPLOYEE表中,前一天或前十天的数据, resign_date是Date类型,带时间的, 怎么才能做到呢? select * from EMPLOYEE
where resign_date = sysdate-1
or resign_date = sysdate -10
where resign_date = sysdate-1
or resign_date = sysdate -10
调试欢乐多
where trunc(resign_date) = trunc(sysdate)-1
or trunc(resign_date) = trunc(sysdate) -10;
where to_char(resign_date,'YYYY-MM-DD') = to_char(sysdate -1,'YYYY-MM-DD')
or to_char(resign_date,'YYYY-MM-DD') = to_char(sysdate -10,'YYYY-MM-DD')
FROM employee
WHERE resign_date = to_date(to_char(SYSDATE - 1, 'YYYY-MM-DD hh24:mi:SS'), 'YYYY-MM-DD hh24:mi:SS'))
OR resign_date = to_date(to_char(SYSDATE - 10, 'YYYY-MM-DD hh24:mi:SS'), 'YYYY-MM-DD hh24:mi:SS'));
这样肯定是不会影响性能的。
select * from EMPLOYEE where DATEDIFF(day,resign_date, GETDATE())<11
你说的是SqlServer的吧。
--这样能够有效利用resign_date上的索引提高查询速度
select *
from employee
where resign_date < tranc(sysdate) and resign_date >= tranc(sysdate)-1
union
select *
from employee
where resign_date < tranc(sysdate)-9 and resign_date >= tranc(sysdate)-10;