Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL - Come eseguire un Oracle RANK() OVER (ORDER BY score DESC)

Aggiungi un'altra variabile:

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 ...