MySQL update statement to store ranking positions

后端 未结 5 2098
死守一世寂寞
死守一世寂寞 2020-12-05 03:41

I\'m trying to get my head around a query and I just can\'t figure it out. I would appreciate if someone give me a pointer. As a simple example of what I\'m trying to achiev

5条回答
  •  隐瞒了意图╮
    2020-12-05 04:14

    In MySQL, you can use row_number.

    Here's an example of using it in a SELECT:

    select @rownum:=@rownum+1 ‘rank’, p.* 
    from player p, (SELECT @rownum:=0) r 
    order by score desc;
    

    If you INSERT INTO using a SELECT like this, you will get your rankings.

提交回复
热议问题