How to close sequence gaps in SQL Server?

后端 未结 4 1073
囚心锁ツ
囚心锁ツ 2021-01-22 20:02

Let\'s say I have a Turtle table. When I run

SELECT * FROM Turtle ORDER BY Sort

I get this:

Id | Name | Sort
2    Leo    1
3           


        
4条回答
  •  囚心锁ツ
    2021-01-22 20:55

    Try this

    SELECT ID, Name, ROW_NUMBER() OVER(ORDER BY Sort) AS Sort FROM Turtle
    

提交回复
热议问题