How to get a row rank?

后端 未结 6 1923
一生所求
一生所求 2021-01-05 04:08

HI,

I actually posted similar (or same?) question yesterday, but I thought I need to post a new question since I have short, but clear question.

I have the f

6条回答
  •  迷失自我
    2021-01-05 04:34

    SET @rank = 0, @prev_val = NULL;
    SELECT id, @rank := IF(@prev_val=points,@rank,@rank+1) AS rank,
    @prev_val := points AS points FROM users ORDER BY points DESC, id asc;
    

    Table:users

提交回复
热议问题