The Peak Stock Protocol:Find the Highest Stock Level per Product Across the Galaxy
Advanced
Display the record with the highest inventory for each product in the galaxy.
The inventory team at Xorthax's trading post needs to know the highest recorded stock level for each product. Write a query to display only the record with the highest quantity available for each product.
Write Your Query
Answer:
with rankedinventory as
(select productid,
quantityavailable,
row_number() over (partition by productid
order by quantityavailable desc) as rank
from inventory)
select productid,
quantityavailable
from rankedinventory
where rank = 1;
Explanation:
This simulates tracking maximum inventory levels to ensure supply efficiency and prevent overstock or shortages.
You’ll practice isolating top records within grouped data and refining results to highlight peak values per category.
This problem is labeled as Advanced. It’s intended for learners who are already comfortable with common window functions and want to push into more complex analytical patterns. Don’t rush — work through the hints one at a time and study the final query structure carefully.
Yes. Every problem comes with optional hints you can reveal one at a time, plus a fully worked step-by-step solution. You decide how much help you want while practicing.
All problems on PracticeWindowFunctions.com are completely free and can be solved without creating an account. Right now there are over 80 practice problems, with new ones added regularly.