Download presentation
Presentation is loading. Please wait.
Published byJodie Arnold Modified over 8 years ago
2
DBI309: Using SQL Server 2012 Window Functions to Solve Common T-SQL Challenges Steven Wang MCITP – BI, Database Developer and DBA
3
Senior DBA Write Blogs @ MSBICOE.com Active Participant One of Top Answers Steven Wang
4
Agenda 2. ********** (Encrypted) 1. Solution Comparison 3.The Nitty- Gritties 5. Performance Comparison Demo
5
Note: The table is simplified for demo Purpose.
8
Note: The table is simplified for demo Purpose. A. 2000B. 2005C. 2008 D. 2012 E. Wrong Syntax
9
A. 2000B. 2005C. 2008 D. 2012 E. Wrong Syntax
10
A. 2000B. 2005C. 2008 D. 2012 E. Wrong Syntax
11
A. B.
13
--Quoted from PostgreSQL 8.4.12 Documentation --SQL Server 2012, BOL
14
SQL: 2008 SQL: 2003 SQL: 2011 SQL: 2006 ISO/ANSI Standard Window Functions introduced No Changes on Window Functions Window Functions Enhanced Extensive Coverage on Window Functions Over Clause (Limited) Rank Functions SQL Server 2005 No new Features for Window Functions SQL Server 2008 Extended support on Over Clause Distribution Functions Offset Functions SQL Server 2012 SQL Server VNext
16
Over()Over( ) Sum(Amount) Over( ) Partition By EmployeeID Order By Period Desc Rows Between Unbounded Preceding And 2 Following
18
Sum(Amount) Over( ) Partition By EmployeeID Order By Period Rows Between Unbounded Preceding And 2 Following Partition By Order by Frame 1 Frame 2 Frame 3 Frame 4 Frame 5 Frame 6
19
FromWhereGroup ByHavingSelectOrder By fwgh SO
20
Agg([All] Expression) Over(…) Agg(Exp) Over(…) Agg(All Exp) Over(…) Agg(Distinct Exp) Over(…) No Distinct Aggregations with Over() Note: Agg refers to all aggregation functions
21
fwgh SO No Distinct in aggregation with Over() A few more
22
A. 1 B. 2 1. 2. C. Both valid D. Both not
24
demo The T-SQL Challenge Solutions
25
Subquery Window Function
26
demo Performance Comparisons
27
Running Total Benchmark
28
SELECT Reverse( Concat(Col, Lead(Col,1) Over(Order by Col Desc) ) ) As Conclusion FROM ( Values ('!!lacirogamsatnahp'), (' era snoitcnuF wodniW') ) T(Col) ORDER BY Col Desc OFFSET 0 ROW FETCH FIRST 1 ROW ONLY;
31
DBI305: Practical Uses and Optimisation of New T-SQL Features in Microsoft SQL Server 2012 - Dave Dustin Exam 70-461: Querying Microsoft SQL Server 2012 Contact Me Later at Email: StevenWang@MSBICOE.comStevenWang@MSBICOE.com LinkedIn Search: Steven Wang Twitter: @MSBICOE Blog: www.MSBICOE.comwww.MSBICOE.com Required Slide *delete this box when your slide is finalised Speakers, please list the Breakout Sessions and Certification Exams that relate to your session. Make sure to indicate how delegates may contact you, if they have questions after the session.
33
Win instant prizes by evaluating this session: aka.ms/mobile
35
Connect. Share. Discuss. newzealand.msteched.com Learning Microsoft Certification & Training Resources microsoft.com/learning TechNet Resources for IT Professionals microsoft.co.nz/technet Resources for Developers microsoft.co.nz/msdn
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.