2. Introduction
What are the windowing functions
Functions that operates/ manipulates on set of rows
Types of windowing functions
Ranking functions - Returns a ranking value for each row
Aggregate functions - Performs calculations on set of values
Analytic functions - Compute moving averages, running
totals, percentages…
Improvements of windowing functions in SQL Server
2012
3. New functionality in SQL Server
2005
OVER() Clause – Used to define a window or user
specified set of rows within a query result set
PARTITION BY Clause - Divides the query result set into
partitions
Ranking functions
Changes in aggregate functions
5. Ranking functions
ROW_NUMBER() - Sequential number of a row within
a partition of a result set
RANK() - Rank of each row within the partition
DENSE_RANK() - rank of rows within the partition of a
result set, without any gaps in the ranking
NTILE() - Distributes the rows in an ordered partition
into a specified number of groups
8. Aggregate functions cont…
Enhancements in SQL Serve 2005
SUM(Column1) OVER (PARTITION BY Column2)
Enhancements in SQL Server 2012
SUM(Column1) OVER (PARTITION BY Column2
ORDER BY Column3)
10. New features with SQL Server 2012
Analytic functions
FIRST_VALUE()
LAST_VALUE()
LEAD()
LAG()
PERCENT_RANK()
PERCENTILE_COUNT()
PERCENTILE_DISC()
CUME_DIST()
11. New features with SQL Server 2012
cont …
Enhancements of Aggregate functions
ODER BY with OVER() clause
Enhancements of defining the partition (window)
ROWS/RANGE
CURRENT ROW
PRECEDING
FOLLOWING
UNBOUNDED