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

发布于 2024-11-10 07:21:38 字数 371 浏览 3 评论 0原文

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 确实存在,则列值为空。

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

Is there a way to get the data from table b with regard to sdp_cust_xref_id, sdp_hour, and sdp_phone when the data does not exist in both tables via the join? If b.sdp_calls does exist, the column values are null.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

So要识趣 2024-11-17 07:21:38

我又读了几遍,我想我知道你想要什么。试试这个。如果表 b 中的值在 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

I read it a few more times and I think I know what you want. Try this. It will give you the values from table b if they are NULL in a:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文