1. Introduction to Window Functions

Window functions perform calculations across a set of table rows related to the current row. Unlike aggregate functions, they do not group the result into a single output row, allowing access to individual rows while performing aggregate-like calculations.

image.png

Syntax of Window Functions

function_name(expression) OVER (
    [PARTITION BY column_name]
    [ORDER BY column_name]
)

2. Common Use Cases of Window Functions

a. Ranking

b. Aggregates

c. Percentile and Distribution

d. Lag/Lead

e. First/Last Value