我有一个Oracle数据库,我有一个显示日期范围的表:
23/12/2011 08/01/2012
06/01/2012 06/01/2012
19/03/2012 19/03/2012
05/04/2012 05/04/2012
06/04/2012 06/04/2012
30/04/2012 30/04/2012
01/05/2012 01/05/2012
02/05/2012 02/05/2012
15/08/2012 15/08/2012
12/10/2012 12/10/2012
01/11/2012 01/11/2012
06/12/2012 06/12/2012
07/12/2012 07/12/2012
08/12/2012 08/12/2012
25/12/2012 25/12/2012
09/01/2013 26/01/2013
20/05/2013 08/06/2013
24/06/2013 13/07/2013
18/01/2013 02/02/2013
24/05/2013 08/06/2013
我希望用一个日期跨越这个表,检查日期不在表格的一对日期中,如下所示:
select *
from table
where table.date NOT BETWEEN
(SELECT DT_START FROM CALENDARIO) AND (SELECT DT_END FROM CALENDARIO))
但BETWEEN不接受数组作为条目,那么有没有办法实现这个?
提前致谢!
答案 0 :(得分:0)
试试这个希望这对你有所帮助
WHERE (d.date1 NOT BETWEEN '2011-11-09 13:08:46' AND '2011-11-11 16:08:46')
OR (d.date2 NOT BETWEEN '2011-11-09 13:08:46' AND '2011-11-11 16:08:46')
OR (d.date3 NOT BETWEEN '2011-11-09 13:08:46' AND '2011-11-11 16:08:46')
答案 1 :(得分:0)
你可以尝试:
select *
from table t1
where not exists (
select null
from CALENDARIO
where t1.my_date between dt_start and dt_end)
答案 2 :(得分:0)
我同意@David Aldrige,要么不存在,要么不存在。
NOT IN和Cross Joining似乎有一个更好的解释计划,如果它是你担心的表现http://sqlfiddle.com/#!4/7159f/6