Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL - Classifica al mese per diversi mesi

Penso che tu voglia che la subquery interna venga aggregata solo per cliente, non per cliente e data:

select t1.*, 
       @rownum := @rownum + 1 AS RANK
from (select CUST, SUM(POLL) as SCORE
      from TABLE
      where EVE_DATE >= '2016-01-01' and EVE_DATE <= '2016-01-31'
      group by CUST
      order by SCORE desc
     ) t1 cross join
     (SELECT @rownum := 0) r 
order by RANK DESC;