๐ŸŽ 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

Deadlock
A situation where two or more transactions permanently block each other by each holding locks that the other needs.
View
A virtual table defined by a SQL query that provides a simplified or restricted view of data from one or more tables.
Soft Delete
A pattern where records are marked as deleted with a flag or timestamp rather than being physically removed from the database.
ORM (Object-Relational Mapping)
A technique that lets you interact with a database using object-oriented code instead of writing raw SQL queries.
Database Index Types
Different index structures (B-tree, Hash, GIN, GiST, BRIN) optimized for various query patterns and data types.
Transaction
A sequence of database operations that are treated as a single unit โ€” either all succeed or all are rolled back.
View All Databases Terms โ†’