答案:
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;
时间: 2024-10-24 00:21:14