PARTITION BY divides rows into groups for calculation:
SELECT
name,
category,
price,
AVG(price) OVER(PARTITION BY category) as category_avg
FROM products;
This calculates the average within each category, while keeping all rows.
For each product, show:
category_avg)Order by category, then price descending.
Run your query to see results