select *,Rank() over (partition by modifieddate order by locationid ) as Rank from Production.ProductInventory?
2、Dense_Rank:功能与Rank相似,但排名的数值是连续的,例如:若同一组内有两个第一名,则该组内下一个名次为第二名
select *,dense_Rank() over (partition by modifieddate order by locationid ) as Rank from Production.ProductInventory
3、Row_Number:根据组显示每一条记录在该组中出现的位置,例如:若有两个第一名,则这两个第一名在一组内排名为1、2,下一组的排序仍从1开始,依次类推
select *,row_number() over (partition by productid order by productid ) as Rank from Production.ProductInventory
select top 13 *,NTILE(2) over (partition by productid order by locationid ) as Rank from Production.ProductInventory
上述四个函数语法格式相同,都要搭配OVER子句,而且要以指定切分或排序记录的方式,OVER子句定议格式如下: Over(【Partition BY <提供数值的描述方式>】 ORDER BY <字段> [DES|ASC]) Partition BY 子句决定排名记录的分组方式,而Order By 子句决定每一组记录要如何排序,如果省略了Partition by 子句,则全部记录为一组