What are Window Functions?

SQL

Window vs GROUP BY

Introduction to Window Functions

Window functions perform calculations across rows while keeping all rows in the result.

The Key Difference

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

Basic Syntax

function_name() OVER (window_specification)

Your Task

Select all products showing:

  • name, category, price
  • The overall average price across ALL products (as avg_price)

    Use AVG(price) OVER() for the window function.

Query Editor
Loading SQL engine...
Loading...
Loading SQL engine...

Run your query to see results