【发布时间】:2014-04-20 09:52:18
【问题描述】:
我有 3 个表格用于登记车辆租赁。
第一个是我用 date_out 和 date_return 插入请求的地方
Table_Solicitation(Id_Solicitation, date_out, date_return)
其他是我注册车辆的地方
Table_Vehicle(Id_Vehicle, description)
最后表批准与否
Table_Approval(Id_Approval, Id_Solicitation, Approved, Id_Vehicle)
现在我需要返回给定 date_out 和 date_return 可用的所有车辆,但是当这些日期在 sql 中为空时我遇到了问题,因为我认为是左连接。
sql是
*select V.Id_Vehicle
from Table_Vehicle V
left join Table_Approval TA on (V.Id_Vehicle = TA.Id_Vehicle)
left join Table_Solicitation TS on (TS.Id_Solicitation= TA.Id_Solicitation)
where
(to_date('$dateOut', 'dd/mm/yyyy hh24:mi') NOT BETWEEN TS.date_out AND TS.date_return)
AND
(to_date('$dateReturn', 'dd/mm/yyyy hh24:mi') NOT BETWEEN TS.date_out AND TS.date_return)
AND
(TS.date_out NOT BETWEEN to_date('$dateOut', 'dd/mm/yyyy hh24:mi') AND to_date('$dateReturn', 'dd/mm/yyyy hh24:mi'))*
现在我有了这些数据
Solicitation 1: from 15/03/2014 13h to 15/03/2014 15h (vehicle 1 is confirmed)
Solicitation 2: from 14/03/2014 13h to 14/03/2014 15h (vehicle 1 is available at the combo box, which is correct).
Solicitation 3: from 14/03/2014 12h to 14/03/2014 14h (vehicle 1 is available at the combo box, but it should not, because conflicts with solicitation 2)
Solicitation 4: from 14/03/2014 12h to 16/03/2014 14h (vehicle 1 is available at the combo box, but it should not, because conflicts with solicitation 1)
我在 sql 中的 between 子句做错了什么?
【问题讨论】: