【问题标题】:Check availability for vehicle检查车辆的可用性
【发布时间】: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 子句做错了什么?

【问题讨论】:

    标签: php oracle


    【解决方案1】:

    你说问题是由于日期的空值。你为什么不只是“isnull()”日期然后你可以比较。有关 isnull 的 oracle 变体,请参见 https://stackoverflow.com/a/3524035/1662973,您可以在其中简单地给它一个随机值,以便您的查询可以正确比较,即,将日期设为 1900 年 1 月 1 日。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-16
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多