php - Query for finding a users rank in game database -
this question has answer here:
- mysql, users rank 4 answers
currently have following information in game table
id name xp 1 bob 11 2 jim 120 3 dan 56 4 oli 32
i want find rank when pulling single user example. want able pull 'jim' rank number 1 , 'bob' rank number 4 example.
i had query seems messed up.
select count(*)+2 game xp > (select xp game id = '$id')
you use this:
select g1.id, count(distinct g2.xp)+1 rank game g1 left join game g2 on g1.xp < g2.xp group g1.id
fiddle here. use distinct or not, depending on after.
Comments
Post a Comment