Window functions perform calculations across rows related to the current row. Unlike GROUP BY, they don't collapse rows—you keep the detail while adding aggregated data.
Window Function Basics#
Ranking Functions#
Aggregate Window Functions#
Moving Averages#
LAG and LEAD#
FIRST_VALUE and LAST_VALUE#
Frame Specifications#
Practical Examples#
Performance Tips#
Conclusion#
Window functions are powerful for analytics queries. They let you compare rows, calculate running totals, and rank data without losing row-level detail. Master ROW_NUMBER, LAG/LEAD, and running aggregates—they solve most common analytical needs.