Answer:
with stocklevels as
(select p.category,
i.productid,
sum(i.quantityavailable) as totalstock
from inventory i
join products p on i.productid = p.productid
group by p.category,
i.productid)
select category,
productid,
totalstock,
ntile(4) over (partition by category
order by totalstock desc) as stocktier
from stocklevels;