Find overlapping (date/time) rows within one table

后端 未结 4 1404
广开言路
广开言路 2021-01-30 12:13

I have a table which stores in each row a meeting with start date/time and end date/time.

meetingID int
meetingStart datetime
meetingEnd datetime

De

4条回答
  •  既然无缘
    2021-01-30 12:28

    Try using this query. It is Quassnoi's solution modified to ignore cases where the end of one booking is the same as the start of another.

    SELECT  m1.meetingID_id, m1.meetingStart , m1.meetingEnd, m2.meetingID_id
    FROM    bookings m1, bookings m2
    WHERE   (m2.meetingStart BETWEEN m1.start AND DATE_SUB(m1.meetingEnd, INTERVAL 1 second)
            OR DATE_SUB(m2.meetingEnd, INTERVAL 1 second) BETWEEN m1.meetingStart AND m1.end)
            AND m1.meetingID_id > m2.meetingID_id
    

提交回复
热议问题