Performing window functions in SQL Server
While most functions and calculations are performed at the reporting level with dashboards and reports, sometimes it may make sense to perform some of these functions at the database level. Some calculation functions are rather complex and can be taxing at the desktop reporting level, but the database on the server level may be more adept at efficiently handling the calculation. Additionally, if the calculation function is performed at the database level, it will provide the same value to all users and maintain consistency. These functions are referred to as window functions as they occur over a defined number of rows and columns. The three main window functions we will cover are as follows:
Rank
Sum
Avg
Rank functions in SQL Server
Ranking is fun! Just ask any college football team. One of the most common functions is to rank a dimension based on a measure from best to worst or first to last. We can apply this function using RANK() over (Order...