SELECT Vehicles.[Vehicle ID]
,Vehicles.Make
,Vehicles.Model
,Vehicles.[Type of Vehicle]
,Vehicles.Year
,Vehicles.Colour
,Vehicles.[Price/ Per Day]
,Vehicles.[Out of Service]
,Booking.End_Rent_Date
,Booking.Start_Rent_Date
FROM Vehicles
INNER JOIN Booking
ON Vehicles.[Vehicle ID] = Booking.[Vehicle ID]
WHERE End_Rent_Date < [enter start date]
OR [enter end date] < Start_Rent_Date;
答案 0 :(得分:1)
SELECT *
FROM Vehicles
WHERE Vehicles.vehicle_id NOT IN (
SELECT Vehicle.vehicle_id
FROM Booking
WHERE (
start_date BETWEEN booking.enter_start_date
AND booking.enter_end_date
)
OR (
end_date BETWEEN booking.enter_start_date
AND booking.enter_end_date
)
)
您必须获取在这些日期之间租用的汽车,并将其从查询中排除,这就是您使用not in
的原因。
查询是正确的,您只需要编辑开始/结束日期部分。
答案 1 :(得分:0)
- 显示所有可用的车辆:
SELECT *
FROM vehicles x1
WHERE x1.vehicle_id NOT IN
(
SELECT vehicle_id
FROM booking x2
WHERE (
enter_start_date BETWEEN x2.start_rent_date AND
x2.end_rent_date)
OR (
enter_end_date BETWEEN x2.start_rent_date AND
x2.end_rent_date)