SQL rank() 用法

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是不能单独使用的
详见

Sql Server2005 Transact-SQL 窗口函数(OVER)

posted @ 2013-12-12 16:36  老皮肉  阅读(3169)  评论(0编辑  收藏  举报