MySQL判断两个时间段是否有重合

集合1(第一个判断)  
    start___________end  
a___________b  

集合2(第三个判断)  
start________________end  
           a_________b  

集合3(第三个判断)  
start___________end  
            a______________b  

集合4  
        start___________end  
a_________________________b  

数据库的字段 start_time, end_time
输入的字段 a,b

SELECT * FROM test_table
WHERE
    (start_time >= a AND start_time <= b)
    OR (start_time <= a AND end_time >= b)
    OR (end_time >= a AND end_time <= b)

你可能感兴趣的:(数据库)