Editing Multiple Rows by Their Order Index

喜夏-厌秋 提交于 2019-12-12 18:42:52

问题


Q: How would I go about using / applying the row number of each row in a query to a certain column in the entire query?

I've added a screenshot to try and make things more obvious:

[The picture is only a simple example]

I would like to be able to directly use the value of the row number in such a context. (Iterate over the values, somehow?)

Thanks in advance. (Sorry if the question is a bit vague)


回答1:


Try this :

;WITH TEST AS 
( 
SELECT *,  
       ROW_NUMBER() OVER (ORDER BY id DESC) AS RowNo 
FROM [UserTable]
) 
UPDATE TEST  
SET  myindex = RowNo


来源:https://stackoverflow.com/questions/7608837/editing-multiple-rows-by-their-order-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!