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