CHAPTER 6
T-SQL Solutions Using Window Functions
The first five chapters of this book described window functions in detail, including both their logical aspects and their optimization aspects. In this sixth and last chapter of the book, I’m going to show how to solve a wide range of querying tasks using window functions. What could be surprising to some is the large number of solutions that rely on the ROW_NUMBER function—by far the most commonly used of the bunch.
The solutions covered in this chapter are
■ Virtual auxiliary table of numbers
■ Sequences of date and time values
■ Sequences of keys
■ Paging
■ Removing duplicates
■ Pivoting
■ Top N per group
■ Emulating IGNORE_NULLS
■ Mode
■ Trimmed mean
■ Running totals ...
Get T-SQL Window Functions: For data analysis and beyond, 2nd Edition 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.