与外部联接相关时,如何从表中选择列的子集?

问题描述

|
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
    

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...