mysql – 将选择查询转换为更新查询

我试图在sql中选择排名,选择查询工作正常如何将此选择转换为更新并更新列.

SET @i=0  ;

SELECT sno, email, points, @i:=@i+1 AS rank FROM user ORDER BY points DESC

如何在表中更新此选择

here得到了查询

最佳答案

SET @i=0; 
UPDATE user SET rank= @i:= (@i+1) ORDER BY points DESC;
点赞