日期:2014-05-18 浏览次数:20537 次
select * from test where (s1 between time1 and time2) or (s2 between time1 and time2)
------解决方案--------------------
--有一个表A,字段:id,time1,time2 --现在有一个查询条件,时间字段s1,s2,如何查询出time1,time2与s1,s2有交集的记录 --比如:time1的值是2012-04-01,time2的值是2012-04-10 --如果s1的值是2012-03-01,s2的值是2012-03-05,那么这两个时间段是没有交集 --如果s1的值是2012-03-01,s2的值是2012-04-05,那么这两个时间段是有交集的 SELECT 1 FROM A WHERE (time1 between s1 and s2) or (time2 between s1 and s2)