Loading…
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.
Downloading SQL engine… (one-time)
This runs entirely in your browser and is cached for next time.