sql >> Base de Datos >  >> RDS >> Mysql

Declaración de actualización de MySQL para almacenar posiciones de clasificación

Esta es una forma de hacerlo:

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;