php – 选择与特定日期重叠的日期范围
发布时间:2020-12-13 16:48:49 所属栏目:PHP教程 来源:网络整理
导读:让我说这个表如下. ID | Startdate | Enddate-----------------------------------------------1 | 2012-12-12 08:00:00 | 2012-12-15 18:30:00-----------------------------------------------2 | 2012-12-11 00:00:00 | 2012-12-16 00:00:00-------------
让我说这个表如下.
ID | Startdate | Enddate ----------------------------------------------- 1 | 2012-12-12 08:00:00 | 2012-12-15 18:30:00 ----------------------------------------------- 2 | 2012-12-11 00:00:00 | 2012-12-16 00:00:00 ----------------------------------------------- 3 | 2012-12-16 08:00:00 | 2012-12-17 18:30:00 ----------------------------------------------- 4 | 2012-12-13 00:00:00 | 2012-12-14 11:30:00 ----------------------------------------------- 所选日期范围为Id 1,2012-12-12 08:00:00至2012-12-15 18:30:00. 正确的Id将是2和4. 解决方法select d1.* from dates d1 inner join dates d2 on d2.id=1 and d1.Startdate<d2.Enddate and d1.Enddate>d2.Startdate where d1.id<>1 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |