开发者

How to update a table with a list of values at a time?

I have

update New开发者_运维问答LeaderBoards set MonthlyRank=(Select RowNumber() (order by TotalPoints desc) from LeaderBoards) 

I tried it this way -

(Select RowNumber() (order by TotalPoints desc) from LeaderBoards) as NewRanks 
 update NewLeaderBoards set MonthlyRank = NewRanks

But it doesnt work for me..Can anyone suggest me how can i perform an update in such a way..


You need to use the WITH statement and a full CTE:

;With Ranks As
    (
    Select PrimaryKeyColumn, Row_Number() Over( Order By TotalPoints Desc ) As Num
    From LeaderBoards
    )
Update NewLeaderBoards
Set MonthlyRank = T2.Num
From NewLeaderBoards As T1
    Join Ranks As T2
        On T2.PrimaryKeyColumn = T1.PrimaryKeyColumn
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜