Modifying a column in a table

前端 未结 2 1764
余生分开走
余生分开走 2021-01-23 10:57

I have the following table test

iD Name    ParentId   GroupID
-----------------------------
1            1        Null
2            1        Null
3         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-23 11:45

    ; WITH CTE 
    AS
     (
     SELECT iDName, ParentId, GroupID,
            DENSE_RANK() OVER (ORDER BY ParentId ASC) RN
      FROM Test
     )
    UPDATE CTE 
    SET GroupID = RN
    

    Working SQL FIDDLE

提交回复
热议问题