MySQL - Finding time overlaps

前端 未结 2 1957
忘了有多久
忘了有多久 2021-01-12 21:57

I have 2 tables in the database with the following attributes:

Booking
=======
booking_id
booking_start
booking_end

resource_booked
===============
booking_         


        
2条回答
  •  我在风中等你
    2021-01-12 22:40

    Wow! I would have never thought of that.. I didn't expect such detailed assistance either, thanks a bunch for all the effort you've put into it! I'm trying to understand and learn from your query :>

    The bookings table has another attribute called creation_date which shows when the booking was made and I was hoping to only show the booking (with overlap in time or clashes) that was made later. So it'd be:

    Booking 1 
    =========
    creation_date - 2000-01-01 13:00:00
    booking_start - 2000-02-24 12:00:00
    booking_end   - 2000-02-24 14:00:00
    
    Booking 2 
    =========
    creation_date - 2000-01-02 15:00:00
    booking_start - 2000-02-24 13:00:00
    booking_end   - 2000-02-24 15:00:00
    

    There is a time overlap between booking 1 and 2 and since booking 2 was made a day later than booking 1, only booking 2 would be shown.

提交回复
热议问题