So I have a table which has start
, end
, taxi
, and driver
. City now wants to get historical look ups by month of who had which cab during month, and when any changes occurred.
So this grabs assignment rows which started in July 2014, ended in July 2014, or were ongoing (started before July and ended after the month or have not yet ended).
My question is whether there is a more efficient or elegant query to get these rows?
SELECT * FROM `taxi_assignments` WHERE
(`start` BETWEEN '2014-07-01 00:00:00' AND '2014-07-31 23:59:59')
OR (`end` BETWEEN '2014-07-01 00:00:00' AND '2014-07-31 23:59:59')
OR (`start` < '2014-07-01 00:00:00' AND
(`end` > '2014-07-31 23:59:59' OR `end` = '0000-00-00 00:00:00')
)