当且仅当客户表中的一个或多个客户位于伦敦时,查询才从客户表中提取数据
我的查询是
select * from Customer
where 'London' = ANY (select city from Customer)
我知道这不是正确的方法,但我想知道这是否也有效。 TIA
您的查询有效,因此这是表达它的一种方式(而且非常聪明)。 Here就是一个例子。
更常见的是,我认为这是anexists
查询:
select c.*
from Customer c
where exists (select 1 from Customer c2 where c2.city = 'London');
这将返回任何城市的所有客户,即使是那些不在伦敦的客户。
您很可能只想回到伦敦的客户,在这种情况下,简单的where city = 'London'
就足够了。
select * from Customer where city ='London' and 1 > (select count(*) from Customer where city='London');