Posts

Showing posts with the label WIndow functions

Learn SQL Server Window functions and Running Totals in five minutes

Image
Hello friends, Welcome back! Someone asked me about this topic so today we have a little bit of T-SQL theory.   As usually I will do my best to explain concepts in the clearest way. We will speak about Window functions (the over clause) and running totals! I hope you enjoy it! Ready? Let’s go!   What are window functions? To understand the logic of window functions, we need to take a step back by noticing that the functions, the ones we have always seen, perform their calculations for each row of the result set. Window functions, on the other hand, have the particularity of operating on a subset of the results (commonly called "window" or “partition”). The returned value is relative to the subset of the data in the sense that it is calculated using values ​​from the rowset extracted from that window. It is important to note that unlike a GROUP BY operator in which the rows of results are aggregated, using the window functions all the rows are kept. The Syntax A window i...