首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

判断一个日期段跟其他的日期段有没有重叠

2012-07-02 
判断一个日期段和其他的日期段有没有重叠select casewhen (not exists(select 1from (select t.contract_s

判断一个日期段和其他的日期段有没有重叠

  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

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

热点排行