How best to get someone's 'rank' from a scores table with php and mysql without looping

前端 未结 3 879
深忆病人
深忆病人 2020-11-29 10:38

My table will hold scores and initials.

But the table wont be ordered.

I can get the total row count easy enough and I know I can get all of them and Order B

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 11:23

    SELECT s1.initials, (
      SELECT COUNT(*)
      FROM scores AS s2
      WHERE s2.score > s1.score
    )+1 AS rank
    FROM scores AS s1
    

提交回复
热议问题