Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL-Update-Anweisung zum Speichern von Ranking-Positionen

So geht's:

SET @r=0;
UPDATE table SET Ranking= @r:= (@r+1) ORDER BY Score DESC;

/* use this if you just want to pull it from the db, but don't update anything */
SET @r=0;
SELECT *, @r:= (@r+1) as Ranking FROM table ORDER BY Score DESC;