Microsoft SQL ServerOVER Clause

Download Microsoft SQL Server for free

Parameters

ParameterDetails
PARTITION BYThe field(s) that follows PARTITION BY is the one that the 'grouping' will be based on

Remarks

The OVER clause determines a windows or a subset of row within a query result set. A window function can be applied to set and compute a value for each row in the set. The OVER clause can be used with:

  • Ranking functions
  • Aggregate functions

so someone can compute aggregated values such as moving averages, cumulative aggregates, running totals, or a top N per group results.

In a very abstract way we can say that OVER behaves like GROUP BY. However OVER is applied per field / column and not to the query as whole as GROUP BY does.

Note#1: In SQL Server 2008 (R2) ORDER BY Clause cannot be used with aggregate window functions (link).

Related Examples

Cumulative Sum