码迷,mamicode.com
首页 > 编程语言 > 详细

HIVE分组排序问题

时间:2016-12-02 18:41:56      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:and   成绩   images   des   http   lang   排名   tab   ima   

技术分享

技术分享

技术分享

技术分享

 

答案:

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;

HIVE分组排序问题

标签:and   成绩   images   des   http   lang   排名   tab   ima   

原文地址:http://www.cnblogs.com/duking1991/p/6126745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!