logo资料库

《Microsoft SQL Server 2012》英文版.pdf

第1页 / 共244页
第2页 / 共244页
第3页 / 共244页
第4页 / 共244页
第5页 / 共244页
第6页 / 共244页
第7页 / 共244页
第8页 / 共244页
资料共244页,剩余部分请下载后查看
Foreword
Introduction
SQL Windowing
Background of Window Functions
Window Functions Described
Set-Based vs. Iterative/Cursor Programming
Drawbacks of Alternatives to Window Functions
A Glimpse of Solutions Using Window Functions
Elements of Window Functions
Partitioning
Ordering
Framing
Query Elements Supporting Window Functions
Logical Query Processing
Clauses Supporting Window Functions
Circumventing the Limitations
Potential for Additional Filters
Reuse of Window Definitions
Summary
A Detailed Look at Window Functions
Window Aggregate Functions
Window Aggregate Functions Described
Supported Windowing Elements
Further Filtering Ideas
Distinct Aggregates
Nested Aggregates
Ranking Functions
Supported Windowing Elements
ROW_NUMBER
NTILE
RANK and DENSE_RANK
Distribution Functions
Supported Windowing Elements
Rank Distribution Functions
Inverse Distribution Functions
Offset Functions
Supported Windowing Elements
LAG and LEAD
FIRST_VALUE, LAST_VALUE, and NTH_VALUE
Summary
Ordered Set Functions
Hypothetical Set Functions
RANK
DENSE_RANK
PERCENT_RANK
CUME_DIST
General Solution
Inverse Distribution Functions
Offset Functions
String Concatenation
Summary
Optimization of Window Functions
Sample Data
Indexing Guidelines
POC Index
Backward Scans
Columnstore Indexes
Ranking Functions
ROW_NUMBER
NTILE
RANK and DENSE_RANK
Improved Parallelism with APPLY
Aggregate and Offset Functions
Without Ordering and Framing
With Ordering and Framing
Distribution Functions
Rank Distribution Functions
Inverse Distribution Functions
Summary
T-SQL Solutions Using Window Functions
Virtual Auxiliary Table of Numbers
Sequences of Date and Time Values
Sequences of Keys
Update a Column with Unique Values
Applying a Range of Sequence Values
Paging
Removing Duplicates
Pivoting
TOP N per Group
Mode
Running Totals
Set-Based Solution Using Window Functions
Set-Based Solutions Using Subqueries or Joins
Cursor-Based Solution
CLR-Based Solution
Nested Iterations
Multirow UPDATE with Variables
Performance Benchmark
Max Concurrent Intervals
Traditional Set-Based Solution
Cursor-Based Solution
Solutions Based on Window Functions
Performance Benchmark
Packing Intervals
Traditional Set-Based Solution
Solutions Based on Window Functions
Gaps and Islands
Gaps
Islands
Median
Conditional Aggregate
Sorting Hierarchies
Summary
Index
Microsoft® SQL Server ® 2012 High-Performance T-SQL Using Window Functions Itzik Ben-Gan
Published with the authorization of Microsoft Corporation by: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, California 95472 Copyright © 2012 by Itzik Ben-Gan All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. ISBN: 978-0-7356-5836-3 1 2 3 4 5 6 7 8 9 LSI 7 6 5 4 3 2 Printed and bound in the United States of America. Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at mspinput@microsoft.com. Please tell us what you think of this book at http://www.microsoft.com/learning/booksurvey. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/ Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, O’Reilly Media, Inc., Microsoft Corporation, nor its resellers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions and Developmental Editor: Ken Jones Production Editor: Kristen Borg Production Services: Curtis Philips Technical Reviewer: Adam Machanic Copyeditor: Roger LeBlanc Indexer: Lucie Haskins Cover Design: Twist Creative • Seattle Cover Composition: Karen Montgomery Illustrators: Robert Romano and Rebecca Demarest
To the Quartet. —Q1
Contents at a Glance Foreword Introduction CHaPTer 1 CHaPTer 2 CHaPTer 3 CHaPTer 4 CHaPTer 5 SQL Windowing a Detailed Look at Window Functions Ordered Set Functions Optimization of Window Functions T-SQL Solutions Using Window Functions Index xi xiii 1 33 81 101 133 211
分享到:
收藏