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 a resultset, called a Window
Basic syntax () OVER (PARTITION BY ORDER BY ) The partition defines the window The order by defines the order of rows within the window
First set of Window functions Row_Number() Rank() Dense_Rank() Ntile( )
PARTITION BY Category ORDER BY Points
Second set of Window functions Lead (Offset) Lag (Offset)
PARTITION BY Category ORDER BY Points
Aggregate Enhancements ( ) OVER (PARTITION BY ORDER BY ROWS BETWEEN AND ) Applies to Sum, Avg, Count, Min, Max
PARTITION BY Category ORDER BY Points ROWS BETWEEN 2 PRECEEDING AND CURRENT ROW