0Pricing
SQL Academy · Lesson

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

  1. OVER, PARTITION BY, ORDER BY
  2. ROW_NUMBER, RANK, DENSE_RANK
  3. LAG, LEAD and Time-Series Patterns
  4. Running Totals and Moving Averages
← Back to SQL Academy