CHAPTER 5

image

Calculating Running and Moving Aggregates

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. Maybe 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 learn how adding an ORDER BY clause to a window aggregate changes everything! You will learn how to add calculations for running and moving aggregates, something often required ...

Get Expert T-SQL Window Functions in SQL Server 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.