© Kathi Kellenberger, Clayton Groom, and Ed Pollack 2019
K. Kellenberger et al.Expert T-SQL Window Functions in SQL Server 2019https://doi.org/10.1007/978-1-4842-5197-3_4

4. Calculating Running and Moving Aggregates

Kathi Kellenberger1 , Clayton Groom2 and Ed Pollack3
(1)
Edwardsville, IL, USA
(2)
Smithton, IL, USA
(3)
Albany, NY, USA
 

Imagine you have been given the task of writing a T-SQL query with running totals of sales by customer. Maybe your first thought is to use a cursor to do it, or possibly you are familiar with some query techniques like self-joins to accomplish the task. If you are running SQL Server 2012 or later, you are in luck! Window functions make it easy to calculate running totals, moving averages, and more.

In this chapter, you will ...

Get Expert T-SQL Window Functions in SQL Server 2019: The Hidden Secret to Fast Analytic and Reporting Queries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.