您的位置:首页 > 其它

hive中数据去重,union,交集和并集等操作语句总结

2017-01-23 10:59 2416 查看
insert overwrite table store  
  select t.p_key,t.sort_word from   
    ( select p_key,  
           sort_word ,  
           row_number()  over(distribute by p_key sort by sort_word) as rn  
     from store)  t  
     where t.rn=1; 

Hive上一个典型表内除重的写法, p_key为除重依据, sort_word 为排序依据,一般为时间   rn为排名。 这里就留下第一名

注意hql 方言中, 表的嵌套要家别名, 字段前加上表别名。 union all 不支持顶层视图。

参考链接:

hive 嵌套使用: http://www.oschina.net/code/snippet_1421929_43903
hive求两个集合的减集: http://www.bkjia.com/yjs/942686.html
SQL 操作结果集 -并集、差集、交集、结果集排序:http://www.cnblogs.com/kissdodog/archive/2013/06/24/3152743.html

关于hive子查询,union,left join :http://www.tuicool.com/articles/MZf6ny

hivejoin 操作小结: http://blog.csdn.net/xyilu/article/details/8112747

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息