MySQL update statement to store ranking positions

后端 未结 5 2101
死守一世寂寞
死守一世寂寞 2020-12-05 03:41

I\'m trying to get my head around a query and I just can\'t figure it out. I would appreciate if someone give me a pointer. As a simple example of what I\'m trying to achiev

5条回答
  •  天命终不由人
    2020-12-05 04:01

    SET @r = 0;
    UPDATE players JOIN (SELECT @r := @r + 1 AS rank, id FROM players ORDER BY rank DESC)
    AS sorted USING(id) SET players.rank = sorted.rank;
    

提交回复
热议问题