日期:2014-05-16  浏览次数:20539 次

判断一个日期段和其他的日期段有没有重叠
  select case
         when (not exists
               (select 1
                  from (select t.contract_startdate, t.contract_enddate
                          from pcmscontract t
                         where t.contract_code = 'SHXLFMHG-JM-TX-2011-004') t1
                 where (contract_startdate between
                       to_date('20101201', 'yyyymmdd') and
                       to_date('20110113', 'yyyymmdd') or
                       contract_enddate between
                       to_date('20101201', 'yyyymmdd') and
                       to_date('20110113', 'yyyymmdd') or
                       to_date('20101201', 'yyyymmdd') between
                       contract_startdate and contract_enddate or
                       to_date('20110113', 'yyyymmdd') between
                       contract_startdate and contract_enddate))) then
          1
         else
          0
       end
  from dual


貌似弄得有点复杂了,不知道有没有更好的办法。


http://blog.sina.com.cn/s/blog_59a59f220100atyz.html

这个同学所说的第二种方法貌似不对,没有发所有的重叠的情况都找出来。