mysql重叠的部分不要,重叠日期范围MySQL

I have the following data;

ID startDate endDate

-----------------------------------------------

1 2010-03-01 10:00:00 2010-03-01 12:00:00

2 2010-03-01 12:30:00 2010-03-01 15:30:00

3 2010-03-01 15:30:00 2010-03-01 18:30:00

What I want to do is check that a start and end date don't fall inside the startDate and endDate ranges in my data.

So for example, the following would be OK;

startDate endDate

-----------------------------------------------

2010-03-01 12:00:00 2010-03-01 12:30:00

2010-03-01 18:30:00 2010-03-01 21:00:00

but the following dates would fail, as they would overlap;

startDate endDate

-----------------------------------------------

2010-03-01 09:00:00 2010-03-01 13:00:00 (overlaps ID 1)

2010-03-01 10:30:00 2010-03-01 11:00:00 (overlaps ID 1)

2010-03-01 18:00:00 2010-03-01 19:00:00 (overlaps ID 3)

I'm pulling my hair out because I can get one or two of the above 3 test date ranges to fail but not all of them.

I am using MySQL.

解决方案

A query to select overlaps (I'd name the columns startTime & endTime though, as Time seems important...):

WHERE

< endDate

AND

> startDate

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值