Answer:
with customertotals as
(select c.customerid,
sum(o.totalamount) as totalspent
from orders o
join customers c on o.customerid = c.customerid
group by c.customerid),
rankedcustomers as
(select customerid,
totalspent,
rank() over (
order by totalspent desc) as rank
from customertotals)
select customerid,
totalspent,
rank
from rankedcustomers
where rank <= 5;