1
2
3
4
5
6
|
WITH tagTab AS (
SELECT YearMonth,
pm=RANK() OVER(PARTITION BY
YearMonth ORDER
BY amount DESC )
FROM SaleTab
) SELECT * FROM tagTab WHERE
pm<=5
|
开窗函数:
http://technet.microsoft.com/zh-cn/library/ms189461(v=sql.105).aspx