select *,Rank() over (partition by modifieddate order by locationid ) as Rank from Production.ProductInventory
select *,dense_Rank() over (partition by modifieddate order by locationid ) as Rank from Production.ProductInventory
select *,row_number() over (partition by productid order by productid ) as Rank from Production.ProductInventory
能够对结果集的数据排序后。依照指定的数量把结果集分成N组,并给予每组一个组编号,分组的方式非常easy,将结果集的总记录数除以N,若有余数M,则前M组都多增一条记录,因此,并不是全部的组都有同样的记录数。但多记录的组最多仅仅有一条记录。
select top 13 *,NTILE(2) over (partition by productid order by locationid ) as Rank from Production.ProductInventory
原文:http://www.cnblogs.com/cynchanpin/p/7221051.html