這是汽車租賃應用程序。 我有表:HQL/JPA找到日期範圍內的可用項目
+-------------------------------------+
|id |start_date |end_date |car_id|
+----+------------+------------+------+
|1 |2017-04-01 |2017-04-10 |1 |
|2 |2017-04-15 |2017-04-20 |1 |
|3 |2017-04-15 |2017-04-20 |2 |
+----+------------+------------+------+
用於查找用戶輸入「userDateStart」和「userDateEnd」之間的所有可用汽車的Hibernate查詢。
select
b.id, b.startDate, b.endDate, b.car.id
from BorrowedDate as b
where :userDateStart not between startDate and endDate
and :userDateEnd not between startDate and endDate
------------
:userDateStart = 2017-04-02 00:00:00
:userDateEnd = 2017-04-10 00:00:00
我的結果是:因爲車ID = 1這個時間是借來的
+-------------------------------------+
|id |start_date |end_date |car_id|
+----+------------+------------+------+
|2 |2017-04-15 |2017-04-20 |1 |
|3 |2017-04-15 |2017-04-20 |2 |
+----+------------+------------+------+
結果是錯誤的。只有car_id = 2應該可用。
看起來正確的我。它在id = 2的行上可用 –
它不正確@JackFlamp,因爲在此時間範圍內car_id = 1不可用。它在其他日期可用。但我想要在userinput的特定時間範圍內有可用的汽車列表。 – twistezo