-- 添加序列号
-- 行号用法:
ROW_NUMBER() OVER (ORDER BY SalesOrderID) AS RowNumber
-- 排序函数的用法:
RANK() OVER(PARTITION BY CountryName ORDER BY TotalAmt, CustomerID DESC) AS Rank
SELECT *,
RANK() OVER(PARTITION BY CountryName ORDER BY TotalAmt, CustomerID DESC) AS RankFROM CTETerritory
来自:http://blog.csdn.net/tjvictor/article/details/4331039