Sql Server批量更新数据

关联上一篇文章

Sql Server批量更新数据

--批量更新排名
UPDATE dbo.OA_UserRanking SET Ranking=cc.Ranking
FROM(
SELECT  ur.ID ,
        ur.EmployeeNo ,
        ur.EmployeeName ,
        ur.Year ,
        ur.DepartmentID ,
        ur.TotalScore ,
        COUNT(1) OVER ( PARTITION BY ur.Year, ur.DepartmentID ) AS TotalUser ,
        DENSE_RANK() OVER ( PARTITION BY ur.Year, ur.DepartmentID ORDER BY ur.TotalScore DESC ) AS Ranking
FROM    dbo.OA_UserRanking ur
) cc
WHERE cc.ID=dbo.OA_UserRanking.ID

Sql Server批量更新数据_第1张图片

你可能感兴趣的:(SQL,Server,sql,数据库,sqlserver)