OVER, PARTITION BY, ORDER BY
Understand the window function model: OVER, PARTITION BY (group), ORDER BY (sort), and how it differs from GROUP BY.
What Is a Window Function?
A window function computes a value across a set of rows related to the current row — without collapsing the result like GROUP BY does. You keep every row AND get an aggregate column.
Basic Example
Average order total across the whole table, on every row:
SELECT id, total,
AVG(total) OVER () AS avg_total
FROM orders;All lessons in this course
- OVER, PARTITION BY, ORDER BY
- ROW_NUMBER, RANK, DENSE_RANK
- LAG, LEAD and Time-Series Patterns
- Running Totals and Moving Averages