100% found this document useful (1 vote)
10 views

[Ebooks PDF] download SQL Server Analytical Toolkit: Using Windowing, Analytical, Ranking, and Aggregate Functions for Data and Statistical Analysis 1st Edition Angelo Bobak full chapters

The document promotes the ebook 'SQL Server Analytical Toolkit' by Angelo Bobak, which focuses on using windowing, analytical, ranking, and aggregate functions for data and statistical analysis. It includes links to download the ebook and additional recommended digital products. The document also provides an overview of the book's contents, including chapters on partitions, analytical functions, and use cases in sales and finance.

Uploaded by

natalborak7l
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
10 views

[Ebooks PDF] download SQL Server Analytical Toolkit: Using Windowing, Analytical, Ranking, and Aggregate Functions for Data and Statistical Analysis 1st Edition Angelo Bobak full chapters

The document promotes the ebook 'SQL Server Analytical Toolkit' by Angelo Bobak, which focuses on using windowing, analytical, ranking, and aggregate functions for data and statistical analysis. It includes links to download the ebook and additional recommended digital products. The document also provides an overview of the book's contents, including chapters on partitions, analytical functions, and use cases in sales and finance.

Uploaded by

natalborak7l
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Get the full ebook with Bonus Features for a Better Reading Experience on ebookmeta.

com

SQL Server Analytical Toolkit: Using Windowing,


Analytical, Ranking, and Aggregate Functions for
Data and Statistical Analysis 1st Edition Angelo
Bobak
https://ebookmeta.com/product/sql-server-analytical-toolkit-
using-windowing-analytical-ranking-and-aggregate-functions-
for-data-and-statistical-analysis-1st-edition-angelo-bobak/

OR CLICK HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

SQL Server Analytical Toolkit: Using Windowing,


Analytical, Ranking, and Aggregate Functions for Data and
Statistical Analysis 1st Edition Angelo Bobak
https://ebookmeta.com/product/sql-server-analytical-toolkit-using-
windowing-analytical-ranking-and-aggregate-functions-for-data-and-
statistical-analysis-1st-edition-angelo-bobak/
ebookmeta.com

Cambridge IGCSE and O Level History Workbook 2C - Depth


Study: the United States, 1919-41 2nd Edition Benjamin
Harrison
https://ebookmeta.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-
benjamin-harrison/
ebookmeta.com

Mathematical Analysis and Analytical Modeling 1st Edition


Ivan Stanimirovic■

https://ebookmeta.com/product/mathematical-analysis-and-analytical-
modeling-1st-edition-ivan-stanimirovic/

ebookmeta.com

Good Son is Sad If He Hears the Name of His Father The


Tabooing of Names in China as a Way of Implementing Social
Values 1st Edition Piotr Adamek
https://ebookmeta.com/product/good-son-is-sad-if-he-hears-the-name-of-
his-father-the-tabooing-of-names-in-china-as-a-way-of-implementing-
social-values-1st-edition-piotr-adamek/
ebookmeta.com
Museum Store the Manager s Guide Basic Guidelines for the
New Museum Store Manager 4th Edition Museum Store
Association (U.S.)
https://ebookmeta.com/product/museum-store-the-manager-s-guide-basic-
guidelines-for-the-new-museum-store-manager-4th-edition-museum-store-
association-u-s/
ebookmeta.com

PYRO Sons of Hell MC Sons of Hell M C Book 3 1st Edition


Rebecca Joyce

https://ebookmeta.com/product/pyro-sons-of-hell-mc-sons-of-hell-m-c-
book-3-1st-edition-rebecca-joyce/

ebookmeta.com

Dirty Secret A Dark Enemies to Lovers Mafia Romance 1st


Edition Bianca Cole

https://ebookmeta.com/product/dirty-secret-a-dark-enemies-to-lovers-
mafia-romance-1st-edition-bianca-cole/

ebookmeta.com

A Touch Of Envy Vices Virtues 1st Edition Alana Winters

https://ebookmeta.com/product/a-touch-of-envy-vices-virtues-1st-
edition-alana-winters/

ebookmeta.com

Only Pieces 1st Edition Edd Tello

https://ebookmeta.com/product/only-pieces-1st-edition-edd-tello/

ebookmeta.com
Optimization of Integer/Fractional Order Chaotic Systems
by Metaheuristics and their Electronic Realization 1st
Edition Esteban Tlelo-Cuautle
https://ebookmeta.com/product/optimization-of-integer-fractional-
order-chaotic-systems-by-metaheuristics-and-their-electronic-
realization-1st-edition-esteban-tlelo-cuautle/
ebookmeta.com
SQL Server Analytical
Toolkit
Using Windowing, Analytical,
Ranking, and Aggregate Functions
for Data and Statistical Analysis

Angelo Bobak
SQL Server Analytical Toolkit: Using Windowing, Analytical, Ranking, and Aggregate
Functions for Data and Statistical Analysis
Angelo Bobak
Hastings On Hudson, NY, USA

ISBN-13 (pbk): 978-1-4842-8666-1 ISBN-13 (electronic): 978-1-4842-8667-8


https://doi.org/10.1007/978-1-4842-8667-8

Copyright © 2023 by Angelo Bobak


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Joan Murray
Development Editor: Laura Berendson
Coordinating Editor: Gryffin Winkler
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza,
Suite 4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub.
Paper in this product is recyclable
I would like to dedicate this book to my wife, Cathy, for all her support
and patience throughout my career and all my book projects. I would
like to thank Apress for this opportunity, specifically Joan Murray, the
acquisition editor, who gave me this chance and Laura Berendson
and Gryffin Winkler for their valuable help and suggestions.
Last but not least, I thank all the technical reviewers for their
suggestions, tips, and corrections. What’s good about this book is
because of them. What’s not so good is entirely due to me!
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Introduction������������������������������������������������������������������������������������������������������������xix

Chapter 1: Partitions, Frames, and the OVER( ) Clause��������������������������������������������� 1


What Are Partitions and Window Frames?������������������������������������������������������������������������������������ 1
What Is an OVER( ) Clause?����������������������������������������������������������������������������������������������������������� 2
History of the OVER( ) Clause and Window Functions������������������������������������������������������������������� 2
The Window Functions������������������������������������������������������������������������������������������������������������������ 3
The OVER( ) Clause������������������������������������������������������������������������������������������������������������������������ 4
Syntax������������������������������������������������������������������������������������������������������������������������������������������� 4
Partitions and Frames������������������������������������������������������������������������������������������������������������������� 6
ROWS Frame Definition����������������������������������������������������������������������������������������������������������������� 8
RANGE Frame Definition������������������������������������������������������������������������������������������������������������� 16
Example 1����������������������������������������������������������������������������������������������������������������������������������� 19
ROWS and RANGE Default Behavior�������������������������������������������������������������������������������������������� 23
Scenario 1����������������������������������������������������������������������������������������������������������������������������� 24
Scenario 2����������������������������������������������������������������������������������������������������������������������������� 24
ROWS and RANGE Window Frame Examples������������������������������������������������������������������������������ 25
Data Set��������������������������������������������������������������������������������������������������������������������������������� 25
Example 2������������������������������������������������������������������������������������������������������������������������������ 29
Example 3������������������������������������������������������������������������������������������������������������������������������ 32
Example 4������������������������������������������������������������������������������������������������������������������������������ 34
Example 5������������������������������������������������������������������������������������������������������������������������������ 38
Summary������������������������������������������������������������������������������������������������������������������������������������ 40

v
Table of Contents

Chapter 2: Sales DW Use Case: Aggregate Functions��������������������������������������������� 43


Sales Data Warehouse���������������������������������������������������������������������������������������������������������������� 43
Sales Data Warehouse Conceptual Model����������������������������������������������������������������������������������� 45
A Word About Performance Tuning���������������������������������������������������������������������������������������������� 50
Aggregate Functions������������������������������������������������������������������������������������������������������������������� 60
COUNT( ), MAX( ), MIN( ), AVG( ), and SUM( ) Functions����������������������������������������������������������� 61
With OVER( )��������������������������������������������������������������������������������������������������������������������������� 63
GROUPING( ) Function������������������������������������������������������������������������������������������������������������ 67
GROUPING: Performance Tuning Considerations������������������������������������������������������������������� 71
STRING_AGG Function����������������������������������������������������������������������������������������������������������� 77
STDEV( ) and STDEVP( ) Functions����������������������������������������������������������������������������������������� 80
STDEV: Performance Tuning Considerations�������������������������������������������������������������������������� 85
VAR( ) and VARP( ) Functions�������������������������������������������������������������������������������������������������� 91
SQL Server 2022: Named Window Example�������������������������������������������������������������������������������� 95
Summary���������������������������������������������������������������������������������������������������������������������������������� 103

Chapter 3: Sales Use Case: Analytical Functions������������������������������������������������� 105


Analytical Functions������������������������������������������������������������������������������������������������������������������ 105
CUME_DIST( ) Function�������������������������������������������������������������������������������������������������������� 106
Performance Considerations����������������������������������������������������������������������������������������������� 112
PERCENT_RANK( ) Function������������������������������������������������������������������������������������������������� 117
Performance Considerations����������������������������������������������������������������������������������������������� 124
High-Performance Strategy������������������������������������������������������������������������������������������������� 127
LAST_VALUE( ) and FIRST_VALUE( )������������������������������������������������������������������������������������� 134
Performance Considerations����������������������������������������������������������������������������������������������� 137
LAG( ) and LEAD( )���������������������������������������������������������������������������������������������������������������� 140
Performance Considerations����������������������������������������������������������������������������������������������� 142
PERCENTILE_CONT( ) and PERCENTILE_DISC( )������������������������������������������������������������������� 147
Performance Considerations����������������������������������������������������������������������������������������������� 152
Using a Report Table������������������������������������������������������������������������������������������������������������ 157
Summary���������������������������������������������������������������������������������������������������������������������������������� 163

vi
Table of Contents

Chapter 4: Sales Use Case: Ranking/Window Functions�������������������������������������� 165


Ranking/Window Functions������������������������������������������������������������������������������������������������������ 165
RANK( ) vs. PERCENT_RANK( )��������������������������������������������������������������������������������������������� 171
Performance Considerations����������������������������������������������������������������������������������������������� 175
RANK( ) vs. DENSE_RANK( )������������������������������������������������������������������������������������������������� 179
Performance Considerations����������������������������������������������������������������������������������������������� 183
NTILE( ) Function Revisited�������������������������������������������������������������������������������������������������� 185
Performance Considerations����������������������������������������������������������������������������������������������� 188
ROW_NUMBER( ) Function��������������������������������������������������������������������������������������������������� 190
Performance Considerations����������������������������������������������������������������������������������������������� 194
Islands and Gaps Example��������������������������������������������������������������������������������������������������� 201
Summary���������������������������������������������������������������������������������������������������������������������������������� 209

Chapter 5: Finance Use Case: Aggregate Functions��������������������������������������������� 211


Aggregate Functions����������������������������������������������������������������������������������������������������������������� 211
COUNT( ) and SUM( ) Functions�������������������������������������������������������������������������������������������� 217
Performance Considerations����������������������������������������������������������������������������������������������� 226
SUM( ) Function������������������������������������������������������������������������������������������������������������������� 234
Performance Considerations����������������������������������������������������������������������������������������������� 238
MIN( ) and MAX( ) Functions������������������������������������������������������������������������������������������������� 244
Performance Considerations����������������������������������������������������������������������������������������������� 250
AVG( ) Function�������������������������������������������������������������������������������������������������������������������� 258
Performance Considerations����������������������������������������������������������������������������������������������� 264
GROUPING Function������������������������������������������������������������������������������������������������������������� 267
Performance Considerations����������������������������������������������������������������������������������������������� 272
STRING_AGG( ) Function������������������������������������������������������������������������������������������������������ 277
STDEV( ) and STDEVP( ) Functions��������������������������������������������������������������������������������������� 278
Performance Considerations����������������������������������������������������������������������������������������������� 286
VAR( ) and VARP( ) Functions������������������������������������������������������������������������������������������������ 297
Ticker Analysis�������������������������������������������������������������������������������������������������������������������������� 302

vii
Table of Contents

More Non-statistical Variance��������������������������������������������������������������������������������������������� 305


Even More Statistical Variance�������������������������������������������������������������������������������������������� 308
Summary���������������������������������������������������������������������������������������������������������������������������������� 311

Chapter 6: Finance Use Case: Ranking Functions������������������������������������������������ 313


Ranking Functions�������������������������������������������������������������������������������������������������������������������� 313
RANK( ) Function������������������������������������������������������������������������������������������������������������������ 314
DENSE_RANK( ) Function����������������������������������������������������������������������������������������������������� 341
NTILE( ) Function������������������������������������������������������������������������������������������������������������������ 355
ROW_NUMBER( ) Function��������������������������������������������������������������������������������������������������� 370
The Data Gaps and Islands Problem����������������������������������������������������������������������������������������� 377
Step 1: Create the First CTE������������������������������������������������������������������������������������������������� 383
Step 2: Set Up the Second CTE to Label Gaps��������������������������������������������������������������������� 386
Step 3: Set Up the Third CTE and Identify Start/Stop Dates of Gaps����������������������������������� 388
Step 4: Generate the Report������������������������������������������������������������������������������������������������ 390
Performance Considerations����������������������������������������������������������������������������������������������� 392
Islands Next������������������������������������������������������������������������������������������������������������������������������ 395
Step 1: Create the First CTE Using LAG( ) and LEAD( )��������������������������������������������������������� 395
Step 2: Create the Second CTE That Labels Islands and Gaps�������������������������������������������� 397
Step 3: Identify Island Start/Stop Dates������������������������������������������������������������������������������� 402
Step 4: Create the Final Report�������������������������������������������������������������������������������������������� 404
Summary���������������������������������������������������������������������������������������������������������������������������������� 408

Chapter 7: Finance Use Case: Analytical Functions���������������������������������������������� 409


Analytical Functions������������������������������������������������������������������������������������������������������������������ 409
CUME_DIST( ) Function�������������������������������������������������������������������������������������������������������� 410
Performance Considerations����������������������������������������������������������������������������������������������� 416
FIRST_VALUE( ) and LAST_VALUE( ) Functions��������������������������������������������������������������������� 420
Performance Considerations����������������������������������������������������������������������������������������������� 424
LAG( ) and LEAD( ) Functions������������������������������������������������������������������������������������������������ 431
LAG( ) Function��������������������������������������������������������������������������������������������������������������������� 431
Performance Considerations����������������������������������������������������������������������������������������������� 435
LEAD( ) Function������������������������������������������������������������������������������������������������������������������ 440

viii
Table of Contents

Performance Considerations����������������������������������������������������������������������������������������������� 442


Memory-Optimized Strategy����������������������������������������������������������������������������������������������� 445
PERCENT_RANK( ) Function������������������������������������������������������������������������������������������������� 450
Performance Considerations����������������������������������������������������������������������������������������������� 453
PERCENTILE_CONT( ) and PERCENTILE_DISC( )������������������������������������������������������������������� 455
PERCENTILE_CONT( )����������������������������������������������������������������������������������������������������������� 455
Performance Considerations����������������������������������������������������������������������������������������������� 459
PERCENTILE_DISC Function������������������������������������������������������������������������������������������������ 462
Performance Considerations����������������������������������������������������������������������������������������������� 465
Multi-memory-enhanced-table Strategy����������������������������������������������������������������������������� 471
Performance Considerations����������������������������������������������������������������������������������������������� 476
Summary���������������������������������������������������������������������������������������������������������������������������������� 482

Chapter 8: Plant Use Case: Aggregate Functions������������������������������������������������� 483


Aggregate Functions����������������������������������������������������������������������������������������������������������������� 484
Data Model�������������������������������������������������������������������������������������������������������������������������������� 485
Data Dictionaries����������������������������������������������������������������������������������������������������������������������� 489
Entity Data Dictionary���������������������������������������������������������������������������������������������������������� 489
Entity Attribute Data Dictionary������������������������������������������������������������������������������������������� 491
Entity Relationship Data Dictionary: Equipment Failure Subject Area��������������������������������� 498
Entity Relationship Data Dictionary: Equipment Status History������������������������������������������� 500
Entity Relationship Data Dictionary: Plant Expense������������������������������������������������������������� 500
COUNT( ) Function��������������������������������������������������������������������������������������������������������������������� 501
AVG( ) Function��������������������������������������������������������������������������������������������������������������������� 512
MIN( ) and MAX( ) Functions������������������������������������������������������������������������������������������������� 514
GROUPING( ) Function���������������������������������������������������������������������������������������������������������� 526
STRING_AGG( ) Function������������������������������������������������������������������������������������������������������ 530
STDEV( ) and STDEVP( ) Functions���������������������������������������������������������������������������������������� 534
VAR( ) and VARP( ) Functions������������������������������������������������������������������������������������������������������ 543
Example 1: Rolling Variance������������������������������������������������������������������������������������������������ 544
Example 2: Variance by Quarter������������������������������������������������������������������������������������������� 547
Example 3: Variance by Year������������������������������������������������������������������������������������������������ 550

ix
Table of Contents

Performance Considerations����������������������������������������������������������������������������������������������������� 553


Memory-Optimized Table Approach������������������������������������������������������������������������������������� 559
Seven-Million-Row Query: Performance Tuning����������������������������������������������������������������������� 570
Summary���������������������������������������������������������������������������������������������������������������������������������� 582

Chapter 9: Plant Use Case: Ranking Functions����������������������������������������������������� 583


Ranking Functions�������������������������������������������������������������������������������������������������������������������� 583
RANK( ) Function������������������������������������������������������������������������������������������������������������������ 584
Performance Considerations����������������������������������������������������������������������������������������������� 588
Performance Considerations����������������������������������������������������������������������������������������������� 594
Performance Considerations����������������������������������������������������������������������������������������������� 600
DENSE_RANK( ) Function����������������������������������������������������������������������������������������������������� 606
Performance Considerations����������������������������������������������������������������������������������������������� 611
NTILE Function��������������������������������������������������������������������������������������������������������������������� 616
Performance Considerations����������������������������������������������������������������������������������������������� 622
ROW_NUMBER( ) Function��������������������������������������������������������������������������������������������������� 626
Performance Considerations����������������������������������������������������������������������������������������������� 630
Summary���������������������������������������������������������������������������������������������������������������������������������� 633

Chapter 10: Plant Use Case: Analytical Functions������������������������������������������������ 635


Analytical Functions������������������������������������������������������������������������������������������������������������������ 635
CUME_DIST( ) Function�������������������������������������������������������������������������������������������������������� 637
Performance Considerations����������������������������������������������������������������������������������������������� 643
FIRST_VALUE( ) and LAST_VALUE( ) Functions��������������������������������������������������������������������� 648
Performance Considerations����������������������������������������������������������������������������������������������� 651
LAG( ) Function��������������������������������������������������������������������������������������������������������������������� 652
Performance Considerations����������������������������������������������������������������������������������������������� 656
LEAD( ) Function������������������������������������������������������������������������������������������������������������������ 665
Performance Considerations����������������������������������������������������������������������������������������������� 667
PERCENT_RANK( ) Function������������������������������������������������������������������������������������������������� 669
Performance Considerations����������������������������������������������������������������������������������������������� 671
PERCENTILE_CONT Function����������������������������������������������������������������������������������������������� 677
Performance Considerations����������������������������������������������������������������������������������������������� 680

x
Table of Contents

PERCENTILE_DISC( ) Function���������������������������������������������������������������������������������������������� 685


Performance Considerations����������������������������������������������������������������������������������������������� 688
Our Usual Report Table Solution������������������������������������������������������������������������������������������ 692
SQL Server Analysis Services��������������������������������������������������������������������������������������������������� 697
Summary���������������������������������������������������������������������������������������������������������������������������������� 714

Chapter 11: Inventory Use Case: Aggregate Functions���������������������������������������� 717


The Inventory Database������������������������������������������������������������������������������������������������������������ 717
The Inventory Data Warehouse������������������������������������������������������������������������������������������������� 719
Loading the Inventory Data Warehouse������������������������������������������������������������������������������������ 721
Aggregate Functions����������������������������������������������������������������������������������������������������������������� 735
COUNT( ), SUM( ), MAX( ), MIN( ), and AVG( ) Functions��������������������������������������������������������� 735
Performance Considerations����������������������������������������������������������������������������������������������� 739
AVG( ) Function�������������������������������������������������������������������������������������������������������������������� 743
Performance Considerations����������������������������������������������������������������������������������������������� 745
Data Warehouse Query�������������������������������������������������������������������������������������������������������� 747
Performance Considerations����������������������������������������������������������������������������������������������� 750
STDEV( ) Function���������������������������������������������������������������������������������������������������������������� 754
Performance Considerations����������������������������������������������������������������������������������������������� 758
Data Warehouse Query�������������������������������������������������������������������������������������������������������� 760
Performance Considerations����������������������������������������������������������������������������������������������� 764
VAR( ) Function��������������������������������������������������������������������������������������������������������������������� 766
Performance Considerations����������������������������������������������������������������������������������������������� 769
Enhancing the SSIS Package���������������������������������������������������������������������������������������������������� 772
Summary���������������������������������������������������������������������������������������������������������������������������������� 783

Chapter 12: Inventory Use Case: Ranking Functions�������������������������������������������� 785


Ranking Functions�������������������������������������������������������������������������������������������������������������������� 786
RANK( ) Function������������������������������������������������������������������������������������������������������������������ 786
Performance Considerations����������������������������������������������������������������������������������������������� 791
Querying the Data Warehouse��������������������������������������������������������������������������������������������� 796
DENSE_RANK( ) Function����������������������������������������������������������������������������������������������������� 802
Performance Considerations����������������������������������������������������������������������������������������������� 805
xi
Table of Contents

NTILE( ) Function������������������������������������������������������������������������������������������������������������������ 809


Performance Considerations����������������������������������������������������������������������������������������������� 813
ROW_NUMBER( ) Function��������������������������������������������������������������������������������������������������� 818
Performance Considerations����������������������������������������������������������������������������������������������� 823
Create an SSRS Report������������������������������������������������������������������������������������������������������������� 824
Report Builder Mini Tutorial������������������������������������������������������������������������������������������������� 828
Create a Power BI Report���������������������������������������������������������������������������������������������������� 855
Summary���������������������������������������������������������������������������������������������������������������������������������� 867

Chapter 13: Inventory Use Case: Analytical Functions����������������������������������������� 869


Analytical Functions������������������������������������������������������������������������������������������������������������������ 869
CUME_DIST( ) Function�������������������������������������������������������������������������������������������������������� 870
Performance Considerations����������������������������������������������������������������������������������������������� 876
FIRST_VALUE( ) and LAST_VALUE( ) Functions��������������������������������������������������������������������� 878
Performance Considerations����������������������������������������������������������������������������������������������� 883
LAG( ) Function��������������������������������������������������������������������������������������������������������������������� 885
Performance Considerations����������������������������������������������������������������������������������������������� 889
LEAD( ) Function������������������������������������������������������������������������������������������������������������������ 894
Performance Considerations����������������������������������������������������������������������������������������������� 900
PERCENT_RANK( ) Function������������������������������������������������������������������������������������������������� 907
Performance Considerations����������������������������������������������������������������������������������������������� 912
PERCENTILE_CONT( ) Function�������������������������������������������������������������������������������������������� 914
Performance Considerations����������������������������������������������������������������������������������������������� 919
PERCENTILE_DISC( ) Function���������������������������������������������������������������������������������������������� 925
Performance Considerations����������������������������������������������������������������������������������������������� 929
Overall Performance Considerations����������������������������������������������������������������������������������� 935
Report Builder Examples����������������������������������������������������������������������������������������������������������� 939
Summary���������������������������������������������������������������������������������������������������������������������������������� 947

Chapter 14: Summary, Conclusions, and Next Steps�������������������������������������������� 949


Summary���������������������������������������������������������������������������������������������������������������������������������� 949
Our Journey������������������������������������������������������������������������������������������������������������������������������ 949
About the Code�������������������������������������������������������������������������������������������������������������������������� 950
xii
Table of Contents

About the Database Folders������������������������������������������������������������������������������������������������������ 952


Data Used in the Examples������������������������������������������������������������������������������������������������������� 952
The Toolkit��������������������������������������������������������������������������������������������������������������������������������� 953
SQL Server�������������������������������������������������������������������������������������������������������������������������������� 954
SSMS���������������������������������������������������������������������������������������������������������������������������������������� 956
The Window Functions�������������������������������������������������������������������������������������������������������������� 959
The Visual Studio Community License�������������������������������������������������������������������������������������� 960
SSAS Projects���������������������������������������������������������������������������������������������������������������������� 962
SSIS Projects����������������������������������������������������������������������������������������������������������������������� 963
Power BI Web Scorecards, Dashboards, and Reports��������������������������������������������������������������� 964
Microsoft Excel Spreadsheets�������������������������������������������������������������������������������������������������� 965
SSAS Server������������������������������������������������������������������������������������������������������������������������������ 966
SSRS Server and Website��������������������������������������������������������������������������������������������������������� 968
Report Builder��������������������������������������������������������������������������������������������������������������������������� 970
Performance Analysis Tools������������������������������������������������������������������������������������������������������ 971
Estimated Query Plans�������������������������������������������������������������������������������������������������������� 972
Live Query Plans������������������������������������������������������������������������������������������������������������������ 973
DBCC������������������������������������������������������������������������������������������������������������������������������������ 974
IO and TIME Statistics���������������������������������������������������������������������������������������������������������� 974
STATISTICS PROFILE������������������������������������������������������������������������������������������������������������ 975
Where to Get the Tools�������������������������������������������������������������������������������������������������������������� 977
SQL Server Developer���������������������������������������������������������������������������������������������������������� 977
Visual Studio Community����������������������������������������������������������������������������������������������������� 978
SQL Server Data Tools��������������������������������������������������������������������������������������������������������� 979
SQL Server SSAS Project Support��������������������������������������������������������������������������������������� 980
SQL Server SSIS Project Support���������������������������������������������������������������������������������������� 981
SQL Server SSRS Project Support��������������������������������������������������������������������������������������� 982
Report Builder���������������������������������������������������������������������������������������������������������������������� 983
Power BI Desktop���������������������������������������������������������������������������������������������������������������� 984
Power BI Server������������������������������������������������������������������������������������������������������������������� 985

xiii
Table of Contents

Microsoft Excel�������������������������������������������������������������������������������������������������������������������� 986


SSMS����������������������������������������������������������������������������������������������������������������������������������� 987
Next Steps��������������������������������������������������������������������������������������������������������������������������������� 988
Thank You!�������������������������������������������������������������������������������������������������������������������������������� 988

Appendix A: Function Syntax, Descriptions���������������������������������������������������������� 989

Appendix B: Statistical Functions����������������������������������������������������������������������� 1009

Index������������������������������������������������������������������������������������������������������������������� 1035

xiv
About the Author
Angelo R. Bobak is a published author with more than three
decades of experience and expertise in the areas of business
intelligence, data architecture, data warehouse design, data
modeling, master data management, and data quality using
the Microsoft BI Stack across several industry sectors such as
finance, telecommunications, engineering, publishing, and
automotive.

xv
Exploring the Variety of Random
Documents with Different Content
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like