12
Chapter 12
Window Functions
Looking sideways without collapsing rows. Partitioning, ordering, running totals, ranks, leads, and lags.
In this chapter
22
queries, easy → advanced
- 001ROW_NUMBER: number each row within a groupRead
- 002RANK vs DENSE_RANK: understand the differenceRead
- 003LAG: compare each employee salary to previousRead
- 004LEAD: see next order total per customerRead
- 005SUM OVER: running total of ordersRead
- 006Moving average: 3-month rolling average revenueRead
- 007NTILE: quartile bucketing of salariesRead
- 008FIRST_VALUE / LAST_VALUE per groupRead
- 009Percent of total using window functionsRead
- 010Gap and Island detection with window functionsRead
- 011Sessionization: group events by sessionRead
- 012Calculate customer retention cohortsRead
- 013Rank all products by price globallyRead
- 014Running count of orders per customerRead
- 0157-day moving average of daily salesRead
- 016Percentage contribution of each product to total salesRead
- 017Customer order value percentile rankingRead
- 018Compare each sale to same day last yearRead
- 019Find longest streak of consecutive sales daysRead
- 020Employee ranking by multiple metricsRead
- 021Classic: find duplicate records and row to keepRead
- 022Compute quartiles with NTILERead