SQL window functions and nested tables
SQL is an easy to learn yet powerful language when it comes to Data Analysis.
There are, however, some functionalities that usually take longer to understand and therefore put into practice.
Window Functions
One of them are the window functions.?Window functions perform calculations across a set of table rows that have some relationship with the current row. They fall into three different categories:
Nested tables
领英推荐
Bonus! I will also introduce the concept of nested tables vs temporary tables.
Temporary tables, as their name implies, exist only temporarily on the database server. As soon as the session in which it has been created is closed, the temporary table will be dropped automatically by SQL Server.
However, most of the times temporary tables can be bypassed by nested tables. This means, you do not need to save a provisional table and then use it, but nest it in the same query and do it all at once.
Let′s put it into practice now!
I have prepared some examples to illustrate both window functions and nested tables using a single table so that you can easily understand it. You can also download the code and play around with it:
Hope you enjoy it!