Analytic Window Functions

Slides:



Advertisements
Similar presentations
Exploring Microsoft Access
Advertisements

Chapter 11 Group Functions
Said Salomon Unitrin Direct Insurance T-SQL Aggregate Functions Said Salomon.
1 McGraw-Hill/Irwin Copyright © 2004, The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5: Introduction to e-Business Systems E-Business: “…the.
©Silberschatz, Korth and Sudarshan22.1Database System Concepts 4 th Edition 1 Extended Aggregation SQL-92 aggregation quite limited  Many useful aggregates.
Database Programming Sections 5– GROUP BY, HAVING clauses, Rollup & Cube Operations, Grouping Set, Set Operations 11/2/10.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
SQL Server Integration Services (SSIS) Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server (MVP) Microsoft Certified Technology Specialist.
ADVANCE T-SQL: WINDOW FUNCTIONS Rahman Wehelie 7/16/2013 ITC 226.
T-SQL: Simple Changes That Go a Long Way DAVE ingeniousSQL.com linkedin.com/in/ingenioussql.
More Windowing Functions KEVIN MCCARTY. What are Windowing Functions Again? Introduced in SQL Server 2005 (SQL 2003 Standard) Used to provide operations.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
05 | SET Operators, Windows Functions, and Grouping Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program.
Background Lots of Demos(That’s it.)
©Silberschatz, Korth and Sudarshan5.1Database System Concepts - 6 th Edition Recursive Queries.
A Glance at the Window Functions. Window Functions Introduced in SQL 2005 Enhanced in SQL 2012 So-called because they operate on a defined portion of.
Explore engage elevate Data Migration Without Tears Mike Feingold Empoint Ltd Tuesday 10th November 2015.
Eugene Meidinger Intermediate Querying: Going Beyond Select
T-SQL Power! Windows That Open Doors Adam
Extending and Creating Dynamics AX OLAP Cubes
Microsoft PowerBI – Advanced Solutions with Microsoft Excel and PowerBI Presented by: Phillip Guglielmi, CPA | Senior BI Consultant and Solutions Architect.
Data Analysis with SQL Window Functions Adam McDonald IT Architect / Senior SQL Developer Smith Travel
SQL Server Analysis Services Fundamentals
What’s new in SQL Server 2017 for BI?
In this session, you will learn to:
Power BI Performance Tips & Tricks
Using Partitions and Fragments
T-SQL: Simple Changes That Go a Long Way
T-SQL: Simple Changes That Go a Long Way
Data Analysis with SQL Window Functions
Window function performance
05 | Using Functions and Aggregating Data
Applying Data Warehouse Techniques
Using Window Ranking, Offset, and Aggregate Functions
I WANT TO HOLD YOUR HAND 1ST TOP 100 SINGLE
Power BI Performance …Tips and Techniques.
Principles of report writing
SQL Server Analysis Services Fundamentals
SQL Server Analysis Services Fundamentals
WINDOW FUNCTIONS ARE YOUR FRIENDS Dejan
T-SQL Window Functions in Microsoft SQL Server Denali
WINDOW FUNCTIONS ARE YOUR FRIENDS Dejan
T-SQL Window Function Deep Dive part 1
Writing Better Queries with Window Functions
Oracle8i Analytical SQL Features
Applying Data Warehouse Techniques
Kasper de Jonge Microsoft Corporation
Power BI for large databases
Table Partitioning Intro and make that a sliding window too!
T-SQL Window function deep dive part 2
Access: SQL Participation Project
Introduction to Window Functions
Applying Data Warehouse Techniques
Processing Analysis Services Tabular Models
Data Analysis with SQL Window Functions
Introduction to T-sql Window functionS
Mary Ledbetter, Systems Sales Engineer
Table Partitioning Intro and make that a sliding window too!
Four Rules For Columnstore Query Performance
Power BI with Analysis Services
Table Partitioning Intro and make that a sliding window too!
CS240B: Assignment1 Winter 2016.
Applying Data Warehouse Techniques
OLAP Functions Order-Dependent Aggregates and Windows in SQL: SQL: same as SQL:1999.
SSIS Data Integration Data Warehouse Acceleration
Chapter 3 Query and Report.
Applying Data Warehouse Techniques
SSIS Data Integration Data Warehouse Acceleration
T-SQL: Simple Changes That Go a Long Way
Presentation transcript:

Analytic Window Functions A practical look at using analytic functions By Gary Melhaff March 15, 2017

About me Over 30 years in IT Certifications & experience in Oracle, Teradata and Sql Server Can be blamed for designing around dozen datamarts and data warehouses since late 1990s Worked for DSHS and DOT in the 1980s, then DNR until 1996, then Weyerhaeuser, Freeinternet.com, consulting gigs, then Washington Mutual Bank for around 7 years Last 7 years as Data Architect at World Vision Product reviews at https://www.itcentralstation.com for SSIS, Wherescape RED, MDS and Melissa Data Quality Presentation abstract: SqlServer Analytic Functions – Practical Uses in Loading Data Warehouses Understanding of the practical application of analytic functions should be an essential element of any SQL developers toolbox. This presentation will cover the basic theory but more importantly will demonstrate actual use cases and demonstrations for everyday use.   Speakers Bio: Gary Melhaff: I’ve been designing and building data warehouses since the late 1990s starting first in Oracle and then using Teradata and more recently using SqlServer. You can read my product reviews at www.itcentralstation.com. I am currently the architect on an enterprise data warehouse that integrates data from multiple sources and updates on an hourly basis.

Environment Data warehouse environment - 100% Microsoft Sources: Microsoft Dynamics CRM Online, Oracle Enterprise Business Suite, Blackbaud CRM (hosted), flat files from multiple sources, Master Data Services (MDS), Adobe Campaign, Oracle NetSuite (new) MelissaData Matchup for SSIS, Attunity OLEDB for Oracle, Kingswaysoft CRM Adapter for SSIS, Visual Studio Online (TFS), BiXpress (for SSIS monitoring&notification), SSIS MultipleHash Master Data Services SSAS tabular (2016 SP1) BI tools: SSRS, PowerBI and Excel VMWare and SSD San

Why you should care Analytic Window Functions are extremely powerful Require very little coding and are easy to use once you learn the basic concepts Workarounds would be relatively complex and less efficient

What are we talking about? Any calculation that is defined by an “OVER()” clause…GROUP BY is not required They give you access to rows outside of the immediate row you are on In other words you can do things like… access aggregate values along with detail rows access row values from other rows besides the current row Examples of practical use Record De-Duplication (picking rows that share same key values) Assigning effective date ranges

Analytic and Ranking Window Functions Lead/Lag First_Value/Last_Value Row_Number Rank Dense_Rank Ntile Cume_Dist Percent_Rank Percentile_Disc Percentile_Cont Functions most often used in ETL operations Aggregate window functions MIN, MAX, AVG, SUM, COUNT, COUNT_BIG CHECKSUM_AGG STDEV, STDEVP, VAR, VARP

Concepts – The Window It is set with the “partition by” clause It’s the set of rows that share the same column(s) Partition clause is optional – if you don’t use it then all rows are the window size Defines the subset of rows to be operated on by the function Partitioning allows us to expand or shrink the size of the rows we are working with

Concepts – The Window Frame Frame set by keywords shown below Defines the subset of rows within the window that the function will utilize Careful - Defaults to start of window up to current row! You set it using ROW or RANGE syntax

Rows in perspective of the window frame Preceding Following Current Row “Unbounded preceding” sets the frame to the start of the window. “Unbounded following” sets the frame to the end of the window. You can also specify an offset of rows preceding or following.

Caveats or Restrictions Cannot use one of these within a “where” or “having” clause! Certain functions will go to the beginning or end of a set of rows but not in- between (eg. first/last) Some options such as window frame size are not available for all functions. For example row_number() only supports the default window frame size.

Example Use Case Window here is the set of rows for each customer Id Rolling11Months_Amt = SUM(ISNULL(Total_Amt,0)) OVER (PARTITION BY Customer_Dim_Id ORDER BY Calendar_Year_Month_Nbr ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) Ordering within window frame Window frame boundaries Used this to segment customers historically since the beginning of time based on sales buckets * SSIS executes this in a dataflow computing rolling total by customer by month for 150 million records across over 8 million customers in just over 16 minutes on 12 vproc server

Demos