Here, we get the sum of
SUM()is an aggregate function, we need a
GROUP BYclause for all non-aggregated columns. This is an aggregate function. The full set of them in T-SQL is available here, but you’ll probably be most familiar with
To turn this into a window function, we slap on an
OVER()and boom! Note: “boom!” only works on SQL Server 2012 and later, so if you’re still on 2008 R2, it’s more of a fizzle than a boom.
Read on for several examples of this nature.