[英]Find differences in both tables without multiple joins
比較兩個數據集后,我想提取信息,例如:
解決這個問題的首選方法是什么? 有沒有辦法做到這一點而不必分別進行 LEFT 和 RIGHT 連接?
我通常會為此使用group by
,所以我不確定對多個連接的引用是什么。
select col1, col2, col3, sum(in_a) as a_cnt, sum(in_b) as b_cnt
from ((select col1, col2, col3, 1 as in_a, 0 as in_b
from a
) union all
(select col1, col2, col3, 0 as in_a, 1 as in_b
from b
)
) ab;
聽起來你想要一個FULL OUTER JOIN
。 這為您提供了兩個表中的所有行,加入了匹配鍵的行。 然后,您可以查看哪些行僅出現在一個表中,並比較兩者中的行的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.