Chapter 9 · Interview Level
19. Top-Selling Category by Quantity
Medium20 XPE-Commerce
Find the product category with the highest total quantity sold. Use a subquery in the FROM clause to first calculate total quantity per category, then select the top one. Return category name and total_quantity.
Tables
- PKidINT
- nameTEXT
- descriptionTEXT
- PKidINT
- nameTEXT
- FKcategory_id→ categories.idINT
- priceREAL
- costREAL
- stock_quantityINT
- created_atTIMESTAMP
- PKidINT
- FKorder_id→ orders.idINT
- FKproduct_id→ products.idINT
- quantityINT
- unit_priceREAL
- discountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.