Presentation is loading. Please wait.

Presentation is loading. Please wait.

T-Sql Dynamic Duo: Window Functions and C0mmon Table Expressions (CTE)

Similar presentations


Presentation on theme: "T-Sql Dynamic Duo: Window Functions and C0mmon Table Expressions (CTE)"— Presentation transcript:

1 T-Sql Dynamic Duo: Window Functions and C0mmon Table Expressions (CTE)

2 About me -Started my technical journey at this local SQL Saturday
-Microsoft Certified Professional -Microsoft Technology Associate: Database Fundamentals Day Job: -Data Analyst with MoneySolvers in Jacksonville, FL Blog at: “How to Become Technical at Any Age” - -Certified Lean Six Sigma Yellow Belt -Weekend Sailor and Wanna-Be ‘Power BI Guru’ -Motto One: ‘Learn as much as you, as fast as you can for as long as you can.’ -Motto Two: ‘Be the best at what you do and learn more to be better!’

3 Session Overview Window Functions and CTEs Explained
Anatomy of a Window Function Ranking Functions Aggregate Functions and Percentages Offset Functions Framing Concepts and Running Totals Median and More Q & A as time allows Information for this presentation taken primarily from Itzik Ben-Gan’s book: Microsoft SQL Server 2012 High Performance T-SQL Using Window Functions.

4 Meet the Real Dynamic Duo
Window Functions Nothing to do with Windows operating system Window Function performs a calculation over a set of rows The Window is defined by the OVER clause The OVER clause may contain a PARTITION BY option , Order BY option and/or Framing options. CTE (Common Table Expressions) Creates a temporary named result set that you can reference within a SELECT, INSERT, UPDATE, or DELETE statement Begin a CTE with a WITH Clause and expression name: With CTE_C as (Select …..) If more than one CTE, you must separate them with commas. Great for troubleshooting code

5 Aggregate Functions SUM() COUNT() MIN() MAX() AVG() Offset Functions Framing LAG LEAD FIRST_VALUE LAST_VALUE NTH VALUE Not implemented with SQL Server 2012 Framing is another filter that further restricts the rows in a partition.

6 Anatomy of a Window Function
Function ( ) OVER Clause (Core Elements: Partitioning….Ordering…Framing) Partition By option: Restricts the rows into smaller sets. Order By option: defines the ordering for the calculation Framing option: Further restricts the rows in the partition and used in Aggregation and Offset functions

7 Demo Time

8 Window Function Recap Partitioning
-Suggest Filtering rather than Grouping -Supported by ALL Window Functions -If Partition By Clause not used, the window is NOT restricted [meaning the ‘default’ partition is to consider the entire result set as one partition. Ordering -Defines the ordering for the Calculation, not presentational ordering -Framing - An additional option to further restrict the rows in the window partition -Window Functions lend themselves to better optimization than subqueries. -Not all Window Functions support all elements -No major changes to Window Functions since release of SQL Server 2012, but 2016 has Batchmode Window Function performance improvements.

9 Resources -’Microsoft SQL Server 2012 High_Performance T-SQL Using Window Functions’ by Itzik Ben-Gan [Great Book!]: Search on Amazon -Intro article to Window Functions: -SQL Window Functions Introdution: -CTE’s: -OVER clause: SQL 2019 Functionality: Video by Itzik Ben-Gan White Papers

10 Questions Contact Info: Blog: LinkedIn: schneider /

11 THE END OF THE PRESENTATION
THE BEGINNING OF A LOVE FOR WINDOW FUNCTIONS AND CTES Join me for the next session: Women In Technology I am on the panel 


Download ppt "T-Sql Dynamic Duo: Window Functions and C0mmon Table Expressions (CTE)"

Similar presentations


Ads by Google