在两个日期之间使用 HQL 查询获取记录
Get records with HQL query between two dates
我想在这段时间里买一辆经济实惠的车
SELECT c FROM Car c WHERE c NOT IN (SELECT r.car from Rental r WHERE r.startDateTime >= :startDate AND r.endDateTime <= :endDate)
此查询无效。例如,我的 endDate
我比 r.endDateTime
我正在尝试使用 BETWEEN 解决此问题,但我的请求是错误的
SELECT c FROM Car c WHERE c NOT IN (SELECT r.car FROM Rental r WHERE :startDate OR :endDate BETWEEN r.startDateTime AND r.endDateTime)
您的查询应如下所示:
SELECT c FROM Car c
WHERE c NOT IN (SELECT r.car FROM Rental r
WHERE (:startDate BETWEEN r.startDateTime AND r.endDateTime)
OR (:endDate BETWEEN r.startDateTime AND r.endDateTime))
我想在这段时间里买一辆经济实惠的车
SELECT c FROM Car c WHERE c NOT IN (SELECT r.car from Rental r WHERE r.startDateTime >= :startDate AND r.endDateTime <= :endDate)
此查询无效。例如,我的 endDate
我比 r.endDateTime
我正在尝试使用 BETWEEN 解决此问题,但我的请求是错误的
SELECT c FROM Car c WHERE c NOT IN (SELECT r.car FROM Rental r WHERE :startDate OR :endDate BETWEEN r.startDateTime AND r.endDateTime)
您的查询应如下所示:
SELECT c FROM Car c
WHERE c NOT IN (SELECT r.car FROM Rental r
WHERE (:startDate BETWEEN r.startDateTime AND r.endDateTime)
OR (:endDate BETWEEN r.startDateTime AND r.endDateTime))