Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

MySQL - Como fazer um Oracle RANK() OVER (ORDER BY score DESC)


Adicione outra variável:
SET @prev_value = NULL;
SET @rank_count = 0;
SET @rank_increasing = 0;
SELECT score
     , @rank_increasing := @rank__increasing + 1 AS row_num
     , CASE
       WHEN @prev_value = score 
          THEN @rank_count
       WHEN @prev_value := score 
          THEN @rank_count := @rank_increasing
       END AS rank
  FROM ...