MySQL 判定两个时间段是否有重叠

原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/17183671.html

 

正向思维

伪代码

(oneStartTime <= otherStartTime && otherStartTime <= oneEndTime) 
|| (oneStartTime <= otherEndTime && otherEndTime <= oneEndTime) 
|| (oneStartTime <= otherStartTime && oneEndTime <= otherEndTime) 
|| (otherStartTime <= oneStartTime && oneEndTime <= otherEndTime)

oneStartTime <= otherEndTime && oneEndTime >= otherStartTime

 

逆向思维

伪代码

!(otherEndTime < oneStartTime || otherStartTime > oneEndTime)

 

posted @ 2023-03-06 14:11  李白与酒  阅读(177)  评论(0编辑  收藏  举报