此查询返回数据集合。但我只需要客户名单。
select * from customer where cust_acnt_nbr = (select cust_acnt_nbr from Asset where dstrct_id = (select dstrct_id from dstrct where dstrct_nm = 'ATLANTA'))
请帮我获取客户名单
答案 0 :(得分:3)
如果子查询可以返回多行,请使用in
代替=
:
select * from customer where cust_acnt_nbr IN
(select cust_acnt_nbr from Asset where dstrct_id IN
(select dstrct_id from dstrct where dstrct_nm = 'ATLANTA'))
答案 1 :(得分:1)
我尽量避免子查询,因为它们的性能很差,并且不清楚你想要实现的目标。您通常可以将其转换为一系列易于阅读的简单连接。
select c.*
from customer c
inner join Asset a on c.cust_acnt_nbr = a.cust_acnt_nbr
inner join dstrct d on d.dstrct_id =a.dstrct_id
where dstrct_nm = 'ATLANTA'