我试图将DATETIME的值与列+时间组件的其他结果进行比较。 基本上,我需要它来显示房间是否有重叠时间比较开始时间+持续时间与房间的其他开始时间。 到目前为止,我已写过这篇文章,但我不确定我真正需要问的是什么。
SELECT roomNo, startDateTime AS `start1`,
(SELECT startDateTime FROM roombooking WHERE (`start1` + duration - startDateTime) > 0 GROUP BY roomNo) AS `start-Time2`
FROM roombooking;
---------------------------------------------
| roomNo | start1 | start2 |
---------------------------------------------
| 1 | 2016-12-8 12:00 | 2016-12-8 12:10|
| 1 | 2016-12-8 12:00 | 2016-12-8 12:15|
| 2 | 2016-12-8 6:00 | 2016-12-8 6:45 |
---------------------------------------------
假设12次会议的持续时间是> 15分钟和2分钟是> 45分钟
答案 0 :(得分:0)
重叠预订表明自我加入:
select rb.*, rb2.*
from roombooking rb join
roombooking rb2
on rb.roomno = rb2.roomno and
rb.startdatetime < rb2.startdatetime + interval rb2.duration minutes and
rb.startdatetime + interval rb.duration minutes > rb.startdatetime;
注意:这假设持续时间以分钟为单位。