HIVE分组排序问题

答案:

hive> select *,row_number() over (partition by product_no order by start_time desc) from table1;

知识点:

1、row_number
  1. hive (test)> select *, row_number() over (partition by sub order by score) as od from t; 
 
2、rank
  1. hive (test)> select *, rank() over (partition by sub order by score) as od from t; 
 
3、dense_ran
  1. hive (test)> select *, dense_rank() over (partition by sub order by score desc) from t;
 
业务实例:
统计每个学科的前三名
  1. select * from (select *, row_number() over (partition by sub order by score desc) as od from t ) t where od<=3;
语文成绩是80分的排名是多少
  1. hive (test)> select od from (select *, row_number() over (partition by sub order by score desc) as od from t )t where sub=‘chinese‘ and score=80;
分页查询
  1. hive (test)> select * from (select *, row_number() over () as rn from t) t1 where rn between 1 and 5;
原文地址:https://www.cnblogs.com/duking1991/p/6126745.html