select customer_id, total, rank
from (
select customer_id, total, @rank := @rank + 1 as rank
from (
select customer_id, sum(total) total
from invoices
group by customer_id
order by sum(total) desc
) t1, (select @rank := 0) t2
) t3
where customer_id = 1;
您可以为此目的使用变量。
dbfiddle在这里