In the previous section, we saw that the OVER clause does not aggregate records into grouped ones. This is the main benefit when it comes to giving raw values side by side with their aggregation. Running aggregates help to calculate what percentage is a certain raw value from a whole set of values, for example. Let's start with a very simple example of a running aggregate.
In the AdventureWorks database, we have a table called Sales.SalesOrderHeader. This table contains data about orders issued by customers. The table contains many columns, but for our games—which we are going to play with running aggregates—we just need a few of them:
- OrderDate: This column contains the date when the order was issued by the customer. ...