Window functions are a specific subset of functions in T-SQL – the dialect of the SQL language Microsoft uses in their database product Microsoft SQL Server – allowing you to create more complex queries. Their application ranges from statistical queries, calculating subtotals, helping you identify duplicate rows, to solving well known problems such as the gaps and islands problem.
With window functions, you can solve some problems in T-SQL more elegantly than before. In a few cases, it allows you to write a set-based query to solve your issue, instead of resorting to a cursor, which is in most cases a slower alternative.
In this tutorial, we’ll give you an introduction to the concepts and usage of the window functions. Learning about these functions and applying them in your everyday programming will make you write better and more efficient T-SQL.
After some introduction work, we’ll go over some of the different categories of window functions. The high-level outline is as follows:
You can use the outline on the left to browse the tutorial or use the arrows “Previous” and “Next”.