我需要一个sql来查找同一房间中事件的重叠日期范围
我需要编写一些SQL来查找发生在同一房间中的重叠日期范围。例如,我有room_num、start_time和stop_time字段。每个记录表示在该房间号码中发生的会话。我需要确定是否有任何具有相同房间号码的会话会相互重叠 你可以试试这样的东西。请注意-我还没有测试它我需要一个sql来查找同一房间中事件的重叠日期范围,sql,date,range,Sql,Date,Range,我需要编写一些SQL来查找发生在同一房间中的重叠日期范围。例如,我有room_num、start_time和stop_time字段。每个记录表示在该房间号码中发生的会话。我需要确定是否有任何具有相同房间号码的会话会相互重叠 你可以试试这样的东西。请注意-我还没有测试它 select e1.room_num, e1.start_time, e1.stop_time e2.start_time, e2.stop_time from events e1, events e2 where
select e1.room_num,
e1.start_time, e1.stop_time
e2.start_time, e2.stop_time
from events e1, events e2
where
(e1.start_time between e2.start_time and e2.end_time
or e1.end_time between e2.start_time and e2.end_time)
and e1.room_num = e2.room_num
如果之间的不起作用(可能是特定于Oracle的),请将其重写为两个独立的>=和。它应该为你指明正确的方向。今后,请提供一些样本数据/表明您在发布问题之前做了一些研究。此问题在当前状态下无法回答