Module 6: Window Functions
Window Functions are often called the “Game Changer” of SQL. They allow you to perform advanced analytical calculations (like running totals, rankings, and year-over-year comparisons) while keeping the individual row-level detail of your data.
Before Window Functions, these tasks required extremely complex and slow self-joins or subqueries.
Learning Objectives
Section titled “Learning Objectives”In this module, you will:
- Understand the anatomy of the
OVER()clause. - Master ranking functions:
ROW_NUMBER,RANK, andDENSE_RANK. - Perform time-series analysis using
LEADandLAG. - Calculate running totals and moving averages.
- Control the scope of your calculations using Window Frames (
ROWS BETWEEN).
Chapters
Section titled “Chapters” 6.1 Window Anatomy Understanding OVER(), PARTITION BY, and ORDER BY.
6.2 Ranking Functions ROW_NUMBER, RANK, DENSE_RANK, and NTILE.
6.3 Value Extraction Looking ahead and behind with LEAD and LAG.
6.4 Window Aggregates Running totals and moving averages.
6.5 Window Frames The power of ROWS BETWEEN for rolling windows.