Answer:
with producttotals as
(select productid,
sum(quantity) as totalquantity
from orderdetails
group by productid),
rankedproducts as
(select productid,
totalquantity,
row_number() over (
order by totalquantity desc) as rank
from producttotals)
select productid,
totalquantity,
rank
from rankedproducts
where rank <= 3;