窗口函数_排序

1、row_number

连续排序,它会为查询出来的每一行记录生成一个序号,依次排序且不会重复,例如1,2,3,4

SELECT names,
       dept,
       row_number() OVER(PARTITION BY dept ORDER BY age DESC) rank 
FROM workers;

2、rank

跳跃排序,如果有两个同一级别时,接下来是第三级别,例如1,2,2,4

select names,
       dept,
       rank() over(partition by dept order by age desc) rank 
from workers;

3、dense_rank

连续排序,如果有两个同一级别时,接下来是第二级别 ,例如1,2,2,3

select names,
       dept,
       dense_rank() over(partition by dept order by age desc) rank 
from workers;

posted @ 2020-11-28 09:59  醴酒微甜  阅读(316)  评论(0编辑  收藏  举报