我正在尝试将日期时间的值与列 时间组件的其他结果进行比较。基本上,我需要它显示房间是否有重叠的时间,将开始时间 持续时间与房间的其他开始时间进行比较。到目前为止,我已经写了这篇文章,但是我不确定我实际上需要问什么。
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分钟
重叠预订建议自加入:
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;
注意:这假定持续时间是在几分钟内测量的。