Obtain sum position (field) ordered from highest to lowest

0

Good morning, I have a query that makes a sum of a score according to user and then orders them from highest to lowest:

select distinct usuario as u, (select sum(puntajeProde) from prodeApuesta 
where usuario = u) as total
from prodeApuesta order by total desc

How can I do to add an autoincrementable id to the query in order to obtain the position where the user was left, eg:

Juan 30 Leo 20 Maria 10

Leo's position is 2

    
asked by Juan 19.10.2017 в 20:04
source

1 answer

1

declaring a variable

SET @rank=0;
select @rank:=@rank+1, distinct usuario as u, (select sum(puntajeProde) from prodeApuesta 
  where usuario = u) as total
  from prodeApuesta order by total desc
    
answered by 19.10.2017 / 20:18
source