🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Databases Advanced

What is Window Function?

An SQL function that performs calculations across a set of rows related to the current row without collapsing the result set.

Window functions compute values over a "window" of rows defined by OVER(). Unlike GROUP BY, they do not reduce the number of rows. Common functions include ROW_NUMBER(), RANK(), DENSE_RANK(), LAG(), LEAD(), SUM() OVER(), and AVG() OVER().

Example: SELECT name, salary, AVG(salary) OVER(PARTITION BY department) as dept_avg FROM employees. Window functions are essential for running totals, rankings, moving averages, and gap-fill operations.

Related Terms

Foreign Key
A column that creates a link between two tables by referencing the primary key of another table.
Replication
The process of copying and maintaining database data across multiple servers for redundancy, failover, and read scaling.
Database Connection Pooling
A technique that maintains a cache of database connections for reuse, reducing the overhead of creating new connections.
Query Optimization
The process of improving database query performance through indexing, query rewriting, and schema design techniques.
SQL
Structured Query Language — the standard language for managing and querying data in relational databases.
PostgreSQL
An advanced open-source relational database known for its reliability, feature richness, and standards compliance.
View All Databases Terms →