hive获取每组数据最大值

hive 分组top N

  • 案例01
    获取历史数据中每个用户最近时间的一条数据
select
  itcode,
  time
from
  (select
     itoode,
     time,
     row_number() over(partion by itcode order by time desc) rn
   from
     tb_his
   )
where 
  rn >= 1
  • 案例02
    获取订单历史数据中每个用户在哪个国家下单最多
select
  itcode,
  country
from
  (select 
     itcode,
     country,
     row_number() over( partition by itcode order by CAST(num AS int) desc ) rn
   from  
     (select
        itcode,
        country,
        count(itcode) as num
      from 
        tb_01
      group by 
        itcode,country
      )
  )
where 
  rn >= 1

你可能感兴趣的:(hive,hive,hive,分组top,N)