如何解决与外部联接相关时,如何从表中选择列的子集?
|select a.cust_xref_id,a.est_hour,a.phone_nbr as number,a.credit_calls,a.credit_rpcs,b.sdp_calls
from #temp0 a
full outer join #temp2 b
on a.cust_xref_id = b.sdp_cust_xref_id
and a.est_hour = b.sdp_hour
and a.phone_nbr = b.sdp_phone
当通过联接在两个表中都不存在数据时,是否有一种方法可以从表b中获得关于sdp_cust_xref_id
,sdp_hour
和sdp_phone
的数据?如果确实存在b.sdp_calls,则列值为空。
解决方法
我再读了几次,我想我知道你想要什么。尝试这个。如果它们在表a中为
NULL
,它将为您提供表b中的值:
select COALESCE(a.cust_xref_id,b.sdp_cust_xref_id) as cust_xref_id,COALESCE(a.est_hour,b.spd_hour) as est_hour,COALESCE(a.phone_nbr,b.spd_phone) as number,a.credit_calls,a.credit_rpcs,b.sdp_calls
from #temp0 a
full outer join #temp2 b
on a.cust_xref_id = b.sdp_cust_xref_id
and a.est_hour = b.sdp_hour
and a.phone_nbr = b.sdp_phone
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。