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 不支持顶层视图,用一个实际中的案例做示例:

 

select * from (
    select * , row_number() over ( partition by name order by num ) as num from xxcx.table
    where dateday = '20170919' 
) where num = 1

 

相关文章:

  • 2022-12-23
  • 2021-08-16
  • 2021-06-08
  • 2021-12-28
  • 2022-12-23
  • 2021-08-02
  • 2021-04-14
  • 2021-11-05
猜你喜欢
  • 2021-10-01
  • 2021-12-10
  • 2021-09-27
  • 2022-01-04
  • 2021-11-01
  • 2021-07-02
  • 2021-11-06
相关资源
相似解决方案