The CFO of Meridian Capital needs a quarterly analysis that standard GROUP BY queries cannot produce. She wants employee rankings within departments, running revenue totals, and month-over-month percentage changes — all in a single result set per query. This requires window functions.
ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) to rank employees within their departmentRANK() to get overall salary rank across the companySUM() OVER (ORDER BY month ROWS UNBOUNDED PRECEDING) for running revenue totalLAG(revenue) to calculate month-over-month changeLEAD(revenue) to preview next month's forecastFUNCTION() OVER (PARTITION BY col ORDER BY col2 ROWS/RANGE frame)
Window functions never collapse rows — every input row produces an output row. Use the Reference window for working templates.