Hive full join 对数 排查异常数据

Hive 专栏收录该内容
121 篇文章 2 订阅

 

select 
t1.*,
t2.*
from (
select  1 as c1 , 'a' as c2 
union all 
select  2 as c1 , 'b' as c2 
union all 
select  3 as c1 , null as c2 
union all 
select  4 as c1 , 'd' as c2 
)t1 
full join 
(
select  2 as c1 , 'b' as c2 
union all 
select  3 as c1 , null as c2 
union all 
select  4 as c1 , 'd4' as c2 
union all 
select  5 as c1 , 'e' as c2 
)t2 
on t1.c1 = t2.c1 
order by coalesce(t1.c1 , t2.c1 ) ; -- 5条记录


select 
t1.*,
t2.*
from (
select  1 as c1 , 'a' as c2 
union all 
select  2 as c1 , 'b' as c2 
union all 
select  3 as c1 , null as c2 
union all 
select  4 as c1 , 'd' as c2 
)t1 
full join 
(
select  2 as c1 , 'b' as c2 
union all 
select  3 as c1 , null as c2 
union all 
select  4 as c1 , 'd4' as c2 
union all 
select  5 as c1 , 'e' as c2 
)t2 
on t1.c1 = t2.c1 
where  t1.c1 is null or  t2.c1 is null or (coalesce(t1.c2,'') <> coalesce(t2.c2,''))
order by coalesce(t1.c1 , t2.c1 ) ; -- 3条记录


select 
t1.*,
t2.*
from (
select  1 as c1 , 'a' as c2 
union all 
select  2 as c1 , 'b' as c2 
union all 
select  3 as c1 , null as c2 
union all 
select  4 as c1 , 'd' as c2 
)t1 
full join 
(
select  2 as c1 , 'b' as c2 
union all 
select  3 as c1 , null as c2 
union all 
select  4 as c1 , 'd4' as c2 
union all 
select  5 as c1 , 'e' as c2 
)t2 
on t1.c1 = t2.c1 
where  (coalesce(t1.c2,'') <> coalesce(t2.c2,''))
order by coalesce(t1.c1 , t2.c1 ) ; -- 3条记录 ,是包含第二种条件的结果的,
-- 所以【t1.c1 is null or  t2.c1 is null】这个条件就不用写了!

一的结果:

二 三的结果:

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值