数据库中分组函数rank() ntile() dense_rank() row_number

---分组排序返回的行是在改组中的第几个位置中间可能间断
select FileId,FileClass,UserId,RANK() over(PARTITION BY fileClass order by UserId) from files
----分组排序返回的行是在改组中的第几个位置中间不间断,组数是根据ntile(参数)中的参数
select FileId,FileClass,UserId,ntile(3) over(PARTITION BY fileClass order by UserId) from files
----分组排序返回的行是在改组中的第几个位置中间不间断
select FileId,FileClass,UserId,DENSE_RANK() over(Partition by FileClass order by UserId ) from Files
----分组排序返回的行是在改组中的顺序位置中间不间断
select FileId,FileClass,UserId,row_number() over(Partition by FileClass order by UserId ) from Files

原文地址:https://www.cnblogs.com/Minghao_HU/p/2565618.html