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

MySQL - Wie man ein Oracle RANK() OVER(ORDER BY score DESC) durchführt

Fügen Sie eine weitere Variable hinzu:

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