hive group by 组内排序,取top(n) select * from ( select col1,col2,col3,row_num() over (partition by id order by col3 DESC) rank ) a where a.rank <= n 介绍: 使用row_number()函数,其中: partition by: 根据id分组.order by: 根据col3排序,降序.