我有这样的Sql返回null从第二选择
select * from Cars where
car_id!=(Select car_id from reservation where reservation_date between '2013-05-13' and '2013-05-15')
我想借此car_id =“”如果这之间没有任何东西日期的查询,但它不工作。
我有这样的Sql返回null从第二选择
select * from Cars where
car_id!=(Select car_id from reservation where reservation_date between '2013-05-13' and '2013-05-15')
我想借此car_id =“”如果这之间没有任何东西日期的查询,但它不工作。
首先检查,如果这是返回正确的价值观
Select car_id
from reservation
where reservation_date
between '2013-05-13' and '2013-05-15'
试试这个:
select *
from Cars
where car_id
not in
(
Select car_id
from reservation
where reservation_date between '2013-05-13' and '2013-05-15'
)
谢谢你的工作 –
@BarışSaçıkara。 。 。如果这个答案适合你,那么你应该接受它。 –
“不是”按draxxxeus的答案将工作中使用,但一旦你得到大量的数据,你的查询会很慢。得到答案的一个不太直观,但在逻辑上等同的方法是这样的:
where car_id in
(select car_id
from cars
except
select car_id
from reservation
etc
)
如果你的数据库支持的语法,它将运行比使用“不是”得更快。对于一些数据库,例如Oracle,您必须使用“minus”而不是“except”。
。 。 “不在”的性能取决于数据库。即使在通常表现不佳的数据库中,通常对于正确的索引也是非常有效的。 –
你在说什么SQL引擎?试试'NVL(subquery,'')' –