DELAPARRA
Index
Color
NL
Category: SQL

OVER

Explained by Updated

What is OVER?

OVER: Turns an aggregate or window function into a window — it computes per row WITHOUT collapsing rows like GROUP BY does. OVER turns an aggregate function into a window function. Instead of collapsing rows into one result, like GROUP BY does, it calculates the value for each row while keeping all rows.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about OVER

How is OVER used in practice?

SELECT name, salary, AVG(salary) OVER () AS company_avg FROM employees shows every employee with the company average next to them. That makes comparisons like "how far above average is each person" a single query.

What should you keep in mind with OVER?

Inside OVER, PARTITION BY restarts the calculation per group and ORDER BY defines the order, which enables running totals and rankings with functions like ROW_NUMBER() and RANK(). Window functions replace many awkward self-joins and much application-side processing. MySQL 8, PostgreSQL and SQLite all support them, so they are available in most current stacks.

What does an example of OVER look like?

SELECT name, salary, AVG(salary) OVER () AS company_avg FROM employees;

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with O

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.