Chapter 8 · Window Functions
19. Price Rank per Category ID
Hard40 XPE-Commerce
For each product, show its name, category_id, price, and its rank within its category based on price (most expensive = rank 1). Use RANK() so tied prices share the same rank. Sort by category_id, then rank.
Tables
- PKidINT
- nameTEXT
- FKcategory_id→ categories.idINT
- priceREAL
- costREAL
- stock_quantityINT
- created_atTIMESTAMP
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.