背景:数据库存放一个时间段,参数传过来一个时间段,看是否有交集数据
数据库:author_start、author_end 参数:startTime、endTime
思路:
1.正向思维:找两个区间的交集
y.author_start<=endTime and (y.author_end + 1)>=startTime
2.逆向思维:找出不冲突的时间取反
not(y.author_start>endTime and (y.author_end + 1)<startTime)
背景:数据库存放一个时间段,参数传过来一个时间段,看是否有交集数据
数据库:author_start、author_end 参数:startTime、endTime
思路:
1.正向思维:找两个区间的交集
y.author_start<=endTime and (y.author_end + 1)>=startTime
2.逆向思维:找出不冲突的时间取反
not(y.author_start>endTime and (y.author_end + 1)<startTime)