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

|
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
    

要回复问题请先登录注册