首页 > 代码库 > HIVE分组排序问题
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分组排序问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。