O'Reilly logo

Inside Microsoft® SQL Server™ 2005: T-SQL Querying by Dejan Sarka, Lubor Kollar, Itzik Ben-Gan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Running Aggregations

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required