SELECT if(count(1)>0,1,0) hasCount FROM xx_table WHERE NOT ( end_time < _startTime OR start_time > _endTime )
其中 _startTime 为传入参数的开始时间
_endTime 为传入参数的结束时间
end_time < _startTime OR start_time > _endTime
不重叠的情况就这两种,然后取反就可以了
本文介绍了一种使用SQL语句判断时间区间是否重叠的方法,通过一个SELECT语句结合NOT操作符和时间条件,实现了高效的时间段判断逻辑。此方法适用于数据库中需要检查时间范围是否冲突的场景。
SELECT if(count(1)>0,1,0) hasCount FROM xx_table WHERE NOT ( end_time < _startTime OR start_time > _endTime )
其中 _startTime 为传入参数的开始时间
_endTime 为传入参数的结束时间
end_time < _startTime OR start_time > _endTime
不重叠的情况就这两种,然后取反就可以了
972
1848

被折叠的 条评论
为什么被折叠?