Top Suppliers of the Trade Federation:Rank Intergalactic Suppliers by Unique Product Diversity
Intermediate
Rank suppliers by the diversity of products they provide.
Xorthax wants to find the top suppliers in terms of the number of unique products they supply. Assign a row number to each supplier based on the number of unique products supplied, with the highest count ranked first.
Write Your Query
Answer:
with supplierproductcounts as
(select supplierid,
count(distinct productid) as productcount
from products
group by supplierid)
select supplierid,
productcount,
row_number() over (
order by productcount desc) as supplier_num
from supplierproductcounts;
Explanation:
This simulates evaluating supplier performance by analyzing how many different products each vendor provides.
You’ll practice ranking entities based on grouped counts and comparing aggregated results across multiple suppliers.
This problem is labeled as Intermediate. It assumes you’ve written a few window function queries before, but you don’t need to be an expert. Use the hints and explanations if you get stuck — they’re there to help you think through the logic.
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.