Answer:
with producttotals as
(select p.category,
p.name as productname,
sum(od.quantity) as totalsales
from orderdetails od
join products p on od.productid = p.productid
group by p.category,
p.name)
select category,
productname,
totalsales,
nth_value(productname, 2) over (partition by category
order by totalsales desc) as secondmostpopular
from producttotals;