Conceptual
Login

SQL Window Function

A window function (ROW_NUMBER, RANK, SUM OVER, LAG) computes a value per row over a partition of related rows defined by OVER (PARTITION BY ... ORDER BY ...), without collapsing rows the way GROUP BY does. This lets rankings and running totals be computed in one pass instead of a self-join or per-row subquery.

Questions this Concept answers

  • Why do window functions so often add a sort to a plan?