mysql查询一个时间区间是否在另一个时间区间内
mysql查询一个时间区间是否在另一个时间区间内
逻辑如下:
limitStartTime <= startTime <= limitEndTime 或 limitStartTime <= endTime <= limitEndTime 或 limitStartTime > startTime and limitEndTime < endtime
假设查询2022-09-07到2022-09-10的数据,Sql如下
SELECT * FROM test WHERE ( ( '2022-09-07' <= start_time AND start_time <= '2022-09-10' ) OR ( '2022-09-07' <= end_time AND end_time <= '2022-09-10' ) OR ( '2022-09-07' > start_time AND '2022-09-10' < end_time )
);