我必须在下面编写一个可用车辆的查询。查询简单表格
我尝试这样做:
select *
from [Rental]
where [Rental].RentEndDate is not null
但它显示了一个已经租来的车— CarID 5
不应该是可租。我该如何解决这个问题?
我必须在下面编写一个可用车辆的查询。查询简单表格
我尝试这样做:
select *
from [Rental]
where [Rental].RentEndDate is not null
但它显示了一个已经租来的车— CarID 5
不应该是可租。我该如何解决这个问题?
试试这个。
Select * from Rental r where r.rentenddate is not null
and not exists (select 1 from rental r1 where r1.carid = r.carid and r1.rentenddate is null)
首先它检查所有没有租金的车。然后有可能汽车返回并再次租用。所以要获得只有可用的汽车,是通过添加不存在的(query_to_search_car_is_on_rent)子句来实现的。
您应该检索只有startdate存在的汽车。
Select * from Rental where rentenddate is null.
如果出租日期为null,则此车尚未退回。 –
那就是我在找什么。谢谢 –
你可以标记答案是正确的。让其他人受益。 –