rank - Ranking sum in mysql -


i have mysql query, trying sum column, , rank total.

here query:

select  @rownum:=@rownum+1 rank, sum(length) total, user_id submissions, (select @rownum:=0) id = 1067 , status = 1 group user_id  order total desc 

this results in:

rank    total    user_id      2      65.25     1360  1      59.50     1151  4      58.00     1250  6      55.75     1374  5      51.25     1154  3      34.75      841 

i think have use inner query grab totals first rank them outter select this:

select @rownum:=@rownum+1 rank,        total,        user_id      (select sum(length) total,             user_id      submissions      id = 1067 , status = 1      group user_id      order total desc)t,(select @rownum:=0)a 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -