Price Rank in Category
For products in categories 2 and 3, return category_id, name, price and price_rank: the rank of the product's price within its category, with the most expensive product ranked 1 and equal prices sharing a rank. Sort by category_id, then price_rank, then product_id.
Hint 1
RANK() OVER (PARTITION BY category_id ORDER BY price DESC).
Reference solution
SELECT category_id,
name,
price,
RANK() OVER (PARTITION BY category_id ORDER BY price DESC) AS price_rank
FROM products
WHERE category_id IN (2, 3)
ORDER BY category_id, price_rank, product_id;
A window function calculates across rows but keeps every row (unlike GROUP BY, which collapses them). PARTITION BY category_id splits the rows into windows, one per category, and RANK() numbers the rows inside each window according to the window's own ORDER BY. Without PARTITION BY the whole result is one window, and the ranks run from 1 to the number of products.