
A look at the anatomy of window functions and their applications
A detailed explanation of how to specify the window for the computation using the OVER clause
You will understand the different window function categories and their application:
Aggregate functions: SUM(), MAX(), MIN(), AVG() etc.
Ranking functions: RANK(), DENSE_RANK(), ROW_NUMBER() etc.
Offset functions: LAG(), LEAD(), FIRST_VALUE(), LAST_VALUE()
You will be able to understand set-based querying versus iterative/cursor programming
Learn you you can transit from iterative programming to set-based programming with the help of window functions
Understand the concepts of the relational model and how SQL Server uses this model to achieve set-based T-SQL querying
After this lecture, you will be able to understand the difference between the ORDER BY clause as part of the OVER clause specification and a presentation ORDER BY clause
Using animation and the RANK() window function for demonstration, you learn how window functions are applied to the window with respect to the current row
You will understand the power of window functions by comparing window function constructs with traditional codes such as joins and CTEs
You will understand how the query engine is optimized for window functions as they make only one visit to the underlying database as opposed to multiple visits by traditional T-SQL
Understand the concept of PARTITIONING within the OVER clause
In this lesson, you learn about the different elements of window functions, especially the elements that are contained in the OVER clause
You will learn about partitioning, and using step-by-step explanation with examples, you will be able to use partitioning in window functions
You learn to use partitions based on a column, as well as understand the meaning of an empty OVER clause parentheses
You will understand the purposes of ordering and framing to further restrict the rows for the window function computation
We use the UNBOUNDED PRECEDING and the CURRENT ROW option of framing to give you detailed explanation of how framing works
You will understand the logical query processing phases and how they apply to window functions
Window functions are only allowed in the SELECT and ORDER BY clauses of the logical query phases.
Learn how to circumvent this limitations by using common table expressions (CTEs) if you meet a situation where you really need to use window functions in the other clauses such as the WHERE clause.
A detailed look of the windows aggregate functions
Understand the dataset that is used as input to the SELECT statement that contains the window functions
Understand the use of the OVER clause used to provide the window specification for the window aggregate functions
Step-by-step, animated description of how the aggregate functions work
Learn how partitioned and non-partitioned aggregate functions compute
You learn how to use window functions to get result sets that contain both detail and aggregate values (partitioned and non-partitioned), such as a result set that output each transaction value as well as the percentage of each transaction partitioned (e.g. percent contribution of the transaction to a customer's total) and non-partitioned (e.g. percent contribution of the transaction to the grand total)
After this lesson, you will be able to use all the options of the ROWS unit for framing:
UNBOUNDED PRECEDING
<n> PRECEDING
<n> FOLLOWING and
CURRENT ROW options
You will be able to create different frames within the same SELECT clause to compute different metrics such as current value, next value, previous value, dynamic averages (all with respect to the current row)
Use the ROW_NUMBER window function to generate sequential (consecutive) row numbers
An introduction to the window offset functions and a detailed look at the LAG and LEAD functions for data analysis
Use the FIRST_VALUE and LAST_VALUE window functions for data analysis
This course is designed and intended for Transact-SQL (T-SQL) developers who are new to window functions and wish to go beyond the traditional query approaches to express set calculations more efficiently using the powerful window functions. Students are not expected to have and knowledge of window functions. The primary purpose of the course is to teach window functions from scratch. This course is designed to bring an understanding of the new dimension that window functions bring to the SQL language.
At the end of the course you will understand the concepts and practical applications of window functions including:
Background of window functions (description of window functions, set-based vs. iterative/cursor programming)
Elements of window functions (Partitioning, Ordering, Framing)
Query elements supporting window functions (logical query processing, clauses supporting window functions, circumventing the limitations)
Aggregate window functions (description of aggregate window functions, supported windowing elements)
Offset window functions (supported window elements, LAG and LEAD functions, FIRST_VALUE and LAST_VALUE functions)
Students are expected to have intermediate to advanced T-SQL querying skills and comfortable with:
Extracting data from multiple tables with joins, subqueries, derived tables, and table expressions (e.g. Common Table Expressions CTEs).
A good understanding of Common Table Expressions (CTEs) will be advantageous. Where window functions on their own cannot achieve a task, we teach how to combine window functions with CTEs to overcome complex data analysis tasks.
At the end of the course, you will be able to:
Replace any existing complex and lengthy codes involving joins and subqueries with a few lines of code using window functions
Bridge the skill gap between iterative/cursor programming and set-based programming
Use window functions to achieve elegant solutions to complex data analysis tasks
The course is video-based using an interactive and animated, custom designed user interface powered by VBA. Analysis are performed using animated, step-by-step processes to explain concepts
All resources needed for the course are included in the last lesson for download:
AcotexDB.sql (open and run in SSMS to create the sample database)
Quizzes
Coding Exercises - Interactive exercises powered by VBA to provide you with a unique learning experience
Solutions to coding exercises - Word document containing the solutions for all the coding exercises