WITH vep AS ( SELECT package.OrderCode , RANK() OVER ( PARTITION BY package.OrderCode ORDER BY package.ID ) AS Index , COUNT(1) OVER ( PARTITION BY package.OrderCode ) AS Count FROM dbo.BookPackages package WITH ( NOLOCK ) ) SELECT TOP 100 * FROM vep WHERE vep.Count > 2
RANK() OVER ( PARTITION BY package.OrderCode ORDER BY package.ID )
rank() 后面带over()窗口函数 over是不能单独使用的
详见