mysql - Sql query for a specific time period -


i trying write mysql query below details-

i have 3 tables

1) booking table column booking_id , journey_start_datetime , journey_end_datetime.

2) driver table column driver driver_id , driver_name.

3) driver_assign table column booking_id, driver_id, busy_start_datetime, busy_end_datetime.

when assign booking driver new entry goes driver_assign table details of booking_id , journey_start_datetime , journey_end_datetime.

i want drivers name not busy given time. ie

lets 1 booking assign driver "john" journey_start_datetime->'2014-06-27 12:00:00' , journey_end_datetime->'2014-06-27 14:00:00'.

now new booking (journey_start_datetime->'2014-06-27 13:00:00' , journey_end_datetime->'2014-06-27 15:00:00') driver john not come.

moving op's code comment question -

select u.driver_name  driver u  u.id not in   (select driver_id    driver_assign dva    ('2014-06-27 13:00:00'>= dva.busy_start_datetime or           '2014-06-27 13:00:00'<= dva.busy_end_datetime         ) ,          ('2014-06-27 15:00:00'>= dva.busy_start_datetime or           '2014-06-27 15:00:00'=< dva.busy_end_datetime         )  ) 

select d.driver_name  driver d       left join driver_assign da on da.driver_id=d.driver_id      da.busy_start_datetime <='2014-06-27 13:00:00'     , da.busy_end_datetime>='2014-06-27 13:00:00' having da.driver_id null 

you need left join , exclude rows not nulls (busy)


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -