相同点
三者均可与 over() 一起使用,对查询进行排序
不同点
row_number() 按照指定条件进行排名,条件相同排名不同,排名连续。
rank() 按照指定条件进行排名,条件相同排名相同,排名不连续。
dense_rank 按照指定条件进行排名,条件相同排名相同,排名连续。
- row_number()与rank()
select *,ROW_NUMBER() over(order by 数学成绩 desc) 排名
from students where 性别 = '男'
select *,RANK() over(order by 数学成绩 desc) 排名
from students where 性别 = '男'
- rank() 和dense_rank()
select *,RANK() over(order by 数学成绩 desc) 排名
from students where 性别 = '男'
select *,dense_RANK() over(order by 数学成绩 desc) 排名
from students where 性别 = '男'