HIVE分组排序问题
Posted OnTheWay_duking
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HIVE分组排序问题相关的知识,希望对你有一定的参考价值。
答案:
hive> select *,row_number() over (partition by product_no order by start_time desc) from table1;
知识点:
1、row_number
hive (test)> select *, row_number() over (partition by sub order by score) as od from t;
2、rank
hive (test)> select *, rank() over (partition by sub order by score) as od from t;
3、dense_ran
hive (test)> select *, dense_rank() over (partition by sub order by score desc) from t;
业务实例:
统计每个学科的前三名
select * from (select *, row_number() over (partition by sub order by score desc) as od from t ) t where od<=3;
语文成绩是80分的排名是多少
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;
分页查询
hive (test)> select * from (select *, row_number() over () as rn from t) t1 where rn between 1 and 5;
以上是关于HIVE分组排序问题的主要内容,如果未能解决你的问题,请参考以下文章