我在这里有点困惑。我正在测试DW中的一些数据质量问题,我需要知道一个表中的LOAN_SID是否与另一个表匹配。我正在使用此查询,但我不确定我是否正确,如果匹配存在问题,如果一切都不好。
所以这是查询:
(select count(LOAN_SID) from DW_DW.AGG_LOAN_SS_MONTHLY
minus
select LOAN_SID from DW_DW.F_LOAN_UNWOUND_TRAN_DAILY)
union all
(
select LOAN_SID from DW_DW.F_LOAN_UNWOUND_TRAN_DAILY
minus
select LOAN_SID from DW_DW.AGG_LOAN_SS_MONTHLY
)
这是另一个:
SELECT LOAN_SID
FROM DW_DW.AGG_LOAN_SS_MONTHLY A
WHERE not EXISTS (SELECT LOAN_SID
FROM DW_DW.F_LOAN_UNWOUND_TRAN_DAILY B
WHERE A.LOAN_SID = B.LOAN_SID);
请帮助!!!
答案 0 :(得分:0)
这给出了两个表中唯一的所有sid。它不是一个非常有效的查询,不应该在没有经过一些测试的情况下在大型表上运行。
select * from
( (select LOAN_SID, 'F_LOAN_UNWOUND_TRAN_DAILY' AS SOURCE
from DW_DW.F_LOAN_UNWOUND_TRAN_DAILY
minus
select LOAN_SID, 'AGG_LOAN_SS_MONTHLY'
from DW_DW.AGG_LOAN_SS_MONTHLY)
UNION ALL
( select LOAN_SID, 'AGG_LOAN_SS_MONTHLY' AS SOURCE
from DW_DW.AGG_LOAN_SS_MONTHLY)
minus
select LOAN_SID, 'F_LOAN_UNWOUND_TRAN_DAILY'
from DW_DW.F_LOAN_UNWOUND_TRAN_DAILY))
获取两个表中的SIDS
select a.LOAD_SID
from DW_DW.AGG_LOAN_SS_MONTHLY a, DW_DW.F_LOAN_UNWOUND_TRAN_DAILY b
where a.LOAN_SID = b.LOAN_SID;