**
hive 的分组排序用法
row_number() over( partition by 分组的字段 order by 排序的字段) as rank(rank 可随意定义表示排序的标识);
row_number() over( distribute by 分组的字段 sort by 排序的字段) as rank(rank 可随意定义表示排序的标识)
注意:
partition by 只能和order by 组合使用
distribute by 只能和 sort by 使用
**
以下是具体sql:
select taaccountid,fundvol from (
select taaccountid ,fundvol,
row_number() over (distribute by taaccountid sort by fundvol desc) as num
from odsdb.bal_fund
)as rs where rs.num<=3;
上述sql意思是,根据taaccountid 分组 根据fundvol desc 降序排序,rs.num<=3 获取fundvol的前三名