Running aggregations are aggregations of data over a sequence (typically temporal). There are many variations of running aggregate problems, and I’ll describe several important ones here.
In my examples, I’ll use a summary table called EmpOrders that contains one row for each employee and month, with the total quantity of orders made by that employee in that month. Run the code in Example 6-1 to create the EmpOrders table, and populate the table with sample data.
Example 6-1. Creating and populating the EmpOrders table
USE tempdb; GO IF OBJECT_ID('dbo.EmpOrders') IS NOT NULL DROP TABLE dbo.EmpOrders; GO CREATE TABLE dbo.EmpOrders ( empid INT NOT NULL, ordmonth DATETIME NOT NULL, qty INT NOT NULL, PRIMARY KEY(empid, ordmonth) ...