Window functions perform calculations across rows while keeping all rows in the result.
GROUP BY collapses rows:
SELECT category, AVG(price) FROM products GROUP BY category;
-- Returns one row per category
Window functions keep all rows:
SELECT name, price, AVG(price) OVER() as overall_avg FROM products;
-- Returns ALL rows with the average added
function_name() OVER (window_specification)
Select all products showing:
avg_price)Use AVG(price) OVER() for the window function.
Run your query to see results