What is Window Function?

A window function calculates a value across a set of related rows, such as a running total or a rank, without collapsing those rows into one.

Window Function explained

Ordinary aggregates with GROUP BY return one row per group. A window function keeps every row and adds a calculated column beside it, for example each order together with the customer's running total.

The OVER clause defines the window: how rows are grouped (PARTITION BY), in what order, and which neighbouring rows count (the frame).

Example

SUM(amount) OVER (ORDER BY order_date) adds a running total column while still listing every order.

How it differs from similar terms

GROUP BY with an aggregate collapses rows; a window function keeps them.

Frequently asked questions

What is Window Function?
A window function calculates a value across a set of related rows, such as a running total or a rank, without collapsing those rows into one.
Can you give an example of Window Function?
SUM(amount) OVER (ORDER BY order_date) adds a running total column while still listing every order.
How is Window Function different from similar terms?
GROUP BY with an aggregate collapses rows; a window function keeps them.