updating columns with a sequence number mysql

后端 未结 3 1310
梦谈多话
梦谈多话 2020-12-01 01:35

I have a table with the columns: (this is only an example I have 50K records)

Name,   Number

Joe     Null
Michael Null
Moses   Null

I to u

3条回答
  •  忘掉有多难
    2020-12-01 01:52

    SET @rank:=0;
    update T
    set Number=@rank:=@rank+1;
    

    UPDATE

    alternative way with one statement

    UPDATE T
    JOIN (SELECT @rank := 0) r
    SET Number=@rank:=@rank+1;
    

提交回复
热议问题