前提
新增的数据不能和数据库的时间有重合部分。
如图,4种重合情况和2种不重合情况。
 
 时间段 a,b
 数据库字段 start_time,end_time
第一种写法
列举每一种重合的情况:
SELECT 
	* 
FROM 
	table
WHERE
	   (start_time >= a and end_time <= b) -- 被包含了
    or (end_time >= a and end_time <=b)
    or (start_time >= a and start_time <=b)
    or (start_time <= a and end_time >=b)
解析:where后的4个条件分别代表了图中4种重合的情况。
但是第一种情况被2和3包含了,所以简化一下写法:
SELECT 
	* 
FROM 
	table 
WHERE
       (end_time >= a and end_time <=b)
    or (start_time >= a and start_time <=b)
    or (start_time <= a and end_time >=b)
第二种写法
判断不重合的,然后取反。
SELECT * FROM table WHERE not (start_time > b or end_time < a);















![壹[1],Xamarin开发](https://img-blog.csdnimg.cn/direct/65acb3728902496696914df418299bf3.png)

![[网络安全]IIS---FTP服务器 、serverU详解](https://img-blog.csdnimg.cn/direct/51c0f28d4c6243f6ac1de0e7a2d759a9.png)

