码迷,mamicode.com
首页 > 其他好文 > 详细

hive 求差集

时间:2017-07-04 13:29:02      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:weight   ber   基本   span   一般来说   bsp   class   去掉   over   

hive求差集的方法

1、什么是差集

set1 - set2,即去掉set1中存在于set2中的数据。

2、hive中计算差集的方法,基本是使用左外链接。

直接上代码

select * from table1 t1 left outer join table2 t2 on t1.id = t2.id where t2.id = null;

 

3、一般来说我们要先去重,使得两个表都变成集合,元素唯一。

先对table2(右表)去重然后再计算差集。

select * from 
  (
    select * from table1 where year=2017 and month=07 and day=01
  ) t1
left outer join
  (
    select * from (select *,row_number() over(partition by id) num from table2 where year=2017 and month=07 and day=01) t where t.num =1) t2
on t1.id = t2.id where t2.id==null;

 

hive 求差集

标签:weight   ber   基本   span   一般来说   bsp   class   去掉   over   

原文地址:http://www.cnblogs.com/kangoroo/p/7116001.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!