gpt4 book ai didi

mysql - 查找重叠日期给无限循环 MySQL

转载 作者:行者123 更新时间:2023-11-29 00:01:11 25 4
gpt4 key购买 nike

假设我有一张给定日期的表:

+-----------+-----------+----+
|StartDate |EndDate |ID |
+-----------+-----------+----+
|2013-08-29 |2014-12-29 |1 |
|2013-08-29 |2013-09-31 |2 |
|2015-01-02 |2015-03-20 |3 |
+-----------+-----------+----+

我想找到冲突的日期,所以代码应该给我 1 作为冲突的日期。当我在 MySQL 中编写这段代码时,它进入了一个无限循环,我希望能得到一点帮助,因为我看不出为什么它不起作用:

select t1.* from dates t1
inner join dates t2
on t2.StartDate > t1.StartDate
and t2.StartDate < t1.EndDate;

谢谢。

最佳答案

不应该吗?:

select t1.*, t2.id as conflict_id
from dates t1
inner join dates t2
on t2.StartDate >= t1.StartDate
and t2.EndDate <= t1.EndDate
and t2.id != t1.id

关于mysql - 查找重叠日期给无限循环 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29737559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com