ranking - Get current rank using mysql -
i've got query rank of rows, order field
set @rank=0; select @rank:=@rank+1 rank, id, ammopacks users group id order ammopacks desc;
how getting rank of "x" id, without ranking them before? don't want know users rank, 1 id.
is possible?
thanks in advance
you can subquery:
select count(*) rank users u u.ammopacks >= (select ammopacks users u2 u2.id = x)
this doesn't same thing. real ranking, users same value of ammopacks
have same rank. original give different users different sequential values in case.
to effect, can do:
select count(*) rank users u u.ammopacks > (select ammopacks users u2 u2.id = x) or (u.ammopacks = (select ammopacks users u2 u2.id = x) , u.id <= x )
Comments
Post a Comment