Synopses & Reviews
Apply powerful window functions in T-SQL—and increase the performance and speed of your queries
Optimize your queries—and obtain simple and elegant solutions to a variety of problems—using window functions in Transact-SQL. Led by T-SQL expert Itzik Ben-Gan, you’ll learn how to apply calculations against sets of rows in a flexible, clear, and efficient manner. Ideal whether you’re a database administrator or developer, this practical guide demonstrates ways to use more than a dozen T-SQL querying solutions to address common business tasks.
Discover how to:
- Go beyond traditional query approaches to express set calculations more efficiently
- Delve into ordered set functions such as rank, distribution, and offset
- Implement hypothetical set and inverse distribution functions in standard SQL
- Use strategies for improving sequencing, paging, filtering, and pivoting
- Increase query speed using partitioning, ordering, and coverage indexing
- Apply new optimization iterators such as Window Spool
- Handle common issues such as running totals, intervals, medians, and gaps
Perform efficient database queries with T-SQL window functions
Get a detailed look into the practical applications of window functions in Transact-SQL—the database programming language built into Microsoft SQL Server. Led by T-SQL expert Itzik Ben-Gan, youll learn how to perform calculations against sets of rows in your database—in a flexible, clear, and efficient manner. Delve into SQL windowing concepts and discover practical uses for various T-SQL window functions.
Discover how to:
- Apply SQL windowing concepts and window function design
- Gain experience with window aggregate, ranking, offset, and distribution functions
- Know when to use SQL ordered set functions, such as hypothetical set functions and inverse distribution functions
- Optimize window functions in SQL Server 2012
- Use practical examples of T-SQL window functions to address common business tasks
About the Author
Itzik Ben-Gan is a principal mentor and a founder of SolidQ. A Microsoft MVP for SQL Server since 1999, Itzik teaches and consults internationally on T-SQL querying, programming, and query tuning. He has written numerous articles for SQL Server Magazine and MSDN, and speaks at industry events such as Microsoft TechEd, DevWeek, PASS, and SQL Server Connections.
Table of Contents
Foreword; Introduction; Who Should Read This Book; Organization of This Book; System Requirements; Code Samples; Acknowledgments; Errata & Book Support; We Want to Hear from You; Stay in Touch; Chapter 1: SQL Windowing; 1.1 Background of Window Functions; 1.2 A Glimpse of Solutions Using Window Functions; 1.3 Elements of Window Functions; 1.4 Query Elements Supporting Window Functions; 1.5 Potential for Additional Filters; 1.6 Reuse of Window Definitions; 1.7 Summary; Chapter 2: A Detailed Look at Window Functions; 2.1 Window Aggregate Functions; 2.2 Ranking Functions; 2.3 Distribution Functions; 2.4 Offset Functions; 2.5 Summary; Chapter 3: Ordered Set Functions; 3.1 Hypothetical Set Functions; 3.2 Inverse Distribution Functions; 3.3 Offset Functions; 3.4 String Concatenation; 3.5 Summary; Chapter 4: Optimization of Window Functions; 4.1 Sample Data; 4.2 Indexing Guidelines; 4.3 Ranking Functions; 4.4 Improved Parallelism with APPLY; 4.5 Aggregate and Offset Functions; 4.6 Distribution Functions; 4.7 Summary; Chapter 5: T-SQL Solutions Using Window Functions; 5.1 Virtual Auxiliary Table of Numbers; 5.2 Sequences of Date and Time Values; 5.3 Sequences of Keys; 5.4 Paging; 5.5 Removing Duplicates; 5.6 Pivoting; 5.7 TOP N Per Group; 5.8 Mode; 5.9 Running Totals; 5.10 Max Concurrent Intervals; 5.11 Packing Intervals; 5.12 Gaps and Islands; 5.13 Median; 5.14 Conditional Aggregate; 5.15 Sorting Hierarchies; 5.16 Summary;