ROW_NUMBER()与PARTITION BY 实例

环境:SQL Server 2008 R2

数据表结构

SELECT A.*
FROM [tbiz_AssScoreWeidu] A
WHERE  A.ProjectID=65 AND A.PersonID=2430 AND A.RelationID=30

 

SELECT A.*
,ROW_NUMBER() OVER
      (
        PARTITION BY A.[WeiduNo]
        ORDER BY  A.[ID] 
      )
      AS rn
FROM [tbiz_AssScoreWeidu] A
WHERE  A.ProjectID=65 AND A.PersonID=2430 AND A.RelationID=3

 

 PARTITION BY 可以跟多个条件 参考

posted @ 2016-12-29 08:47  轴轴  阅读(411)  评论(0编辑  收藏  举报