Answer:
with customerspending as
(select o.customerid,
p.category,
sum(od.quantity * p.price) as totalspending
from orders o
join orderdetails od on o.orderid = od.orderid
join products p on od.productid = p.productid
group by o.customerid,
p.category)
select customerid,
category,
totalspending,
row_number() over (partition by category
order by totalspending desc) as rank
from customerspending;