php - Query for finding a users rank in game database -


this question has answer here:

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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -