[英]How to Check join value for null and lookup in the other tables
If the join values of accomm_bk
and type_bk
is Null then how to lookup values in tables say lookup_accomm_bk
, lookup_type_bk
. 如果
accomm_bk
和type_bk
的连接值为Null,则如何在表中查找值表示lookup_accomm_bk
和lookup_type_bk
。
Any help will be appreciated. 任何帮助将不胜感激。
select accomm_bk,type_bk
from
staging.contract a
left join dim.accomm_dim b on (a.accomm_id)= b.accomm_hash
left join dim.type_dim c on (a.accomm_id)= c.type_hash
IF Result is NULL, then how to lookup staging.contract a
with tables lookup_accomm_bk
for column accomm_bk
and lookup_type_bk
for column type_bk
and get values. 如果结果为null,那么如何查找
staging.contract a
有桌子lookup_accomm_bk
列accomm_bk
和lookup_type_bk
列type_bk
和获取值。
Example 例
accomm_bk | type_bk
--------------------
NULL | NULL
If Result is NULL, then how to lookup staging.contract a with tables lookup_accomm_bk for column accomm_bk and lookup_type_bk for column type_bk and get values.
如果Result为NULL,则如何查找staging。使用表lookup_accomm_bk的accomm_bk列和表lookup_type_bk的type_bk列来契约a并获取值。
You would need to add two more LEFT JOIN
s to your query to link the contract
table to tables lookup_accomm_bk
and lookup_type_bk
. 您将需要在查询中再添加两个
LEFT JOIN
,以将contract
表链接到表lookup_accomm_bk
和lookup_type_bk
。
Then use the COALESCE
function to display the looked up values if they can't be found in accomm_dim
and type_dim
. 如果在
accomm_dim
和type_dim
找不到查找的值,则使用COALESCE
函数显示查找的值。
Here is a skeleton for the query (you need to define the proper ON
clauses for the additional LEFT JOIN
s) : 这是查询的框架(您需要为其他
LEFT JOIN
定义适当的ON
子句):
select
COALESCE(b.accomm_bk, lb.accomm_bk),
COALESCE(c.type_bk, lc.type_bk)
from
staging.contract a
left join dim.accomm_dim b on (a.accomm_id)= b.accomm_hash
left join dim.type_dim c on (a.accomm_id)= c.type_hash
left join dim.lookup_accomm_bk lb on ...
left join dim.lookup_type_bk lc on ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.