Rank
1.函數說明
RANK() 排序相同時會重復,總數不會變
DENSE_RANK() 排序相同時會重復,總數會減少
ROW_NUMBER() 會根據順序計算
2.數據准備(手巧時切記用tab分開,不要用空格,會報錯0
孫悟空 語文 87
孫悟空 數學 95
孫悟空 英語 68
大海 語文 94
大海 數學 56
大海 英語 84
宋宋 語文 64
宋宋 數學 86
宋宋 英語 84
婷婷 語文 65
婷婷 數學 85
婷婷 英語 78
3.需求
計算每門學科成績排名。
4.數據導入
(1)數據導入hive數據庫
//創建數據表
create table score( > > name string, > > subject string, > > score int) > > row format delimited fields terminated by "\t";//一行中每列數據用\t切分
load data local inpath '/home/hadoop/file/score' into table score;/home/hadoop/file/score是我的文件路徑和文件名
5.查詢語句
select name,subject,score, rank() over(partition by subject order by score desc) rp, dense_rank() over(partition by subject order by score desc) drp, row_number() over(partition by subject order by score desc) rmp from score;
6.結果顯示