Hive ,开窗函数,sum,row_number,dense_rank,percent_rank

1  排序:row_number(),dense_rank()

select  
sku_id,sku_name,category_id3,sales_count,price,
sales_count*price as s1,
dense_rank() over(partition by category_id3 order by s1 desc) as r2 -- Invalid table alias or column reference 's1
from sales_info  where dt = '2019-04-26';


select  
sku_id,sku_name,category_id3,sales_count,price,
sales_count*price as s1,
dense_rank() over(partition by category_id3 order by sales_count*price desc) as r2,  --按照GMV排名,降序
row_number() over(partition by category_id3 order by sales_count*price desc) as r3
from sales_info  where dt = '2019-04-26';

Hive ,开窗函数,sum,row_number,dense_rank,percent_rank_第1张图片

《hive的row_number()、rank()和dense_rank()的区别以及具体使用》https://blog.csdn.net/qq_20641565/article/details/52841345

row_number:不管排名是否有相同的,都按照顺序:1,2,3…..n 
rank:排名相同的名次一样,同一排名有几个,后面排名就会跳过几次:1,2,2,4,5.....
dense_rank:排名相同的名次一样,且后面名次不跳跃:1,2,2,3,4,5......

---------------------------------

2  百分比:percent_rank()

select  
sku_id,sku_name,category_id3,sales_count,price,
sales_count*price as s1,
dense_rank() over(partition by category_id3 order by sales_count*price) as r2,  --按照GMV排名,降序
percent_rank()  over(partition by category_id3 order by sales_count*price) as p1 --百分比,击败多少
from sales_info  where dt = '2019-04-26';

Hive ,开窗函数,sum,row_number,dense_rank,percent_rank_第2张图片

end 

你可能感兴趣的:(Hive)