๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout 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

Prepared Statement
A pre-compiled SQL template that uses parameters instead of literal values, preventing SQL injection and improving performance.
JSONB
PostgreSQL's binary JSON data type that stores JSON documents with indexing, querying, and manipulation capabilities.
ACID
A set of four properties (Atomicity, Consistency, Isolation, Durability) that guarantee reliable database transactions.
Deadlock
A situation where two or more transactions permanently block each other by each holding locks that the other needs.
JOIN
An SQL operation that combines rows from two or more tables based on a related column between them.
Materialized View
A database object that stores the precomputed result of a query, offering faster reads at the cost of periodic refresh.
View All Databases Terms โ†’