Posts

Showing posts with the label window function

SQL Server 2022 and windowing improvements. Learn SQL with me!

Image
Hi guys, In the last four posts we talked about the T-SQL news that SQL Server 2022 brought us. SQL Server 2022 and the DATE_BUCKET function. Work more easily with dates  SQL Server 2022 and the GREATEST / LEAST T-SQL commands   SQL Server 2022 and the STRING_SPLIT command .. string splitting made easy!  SQL Server 2022 and the GENERATE-SERIES command .. a T-SQL language enhancement  Today we will talk about another T-SQL extension.  We will talk about the Window clause in the window functions . As always, I will try to be as clear as possible! Enjoy this post!   The Window Clause With SQL Server 2022, Microsoft introduce in the window functions the concept of window . For the sake of truth this is not a feature invented by Microsoft because this concept is part of the ISO/IEC SQL standard. If you doesn't know what a window function is, you can read here: Learn SQL Server Window functions and Running Totals in five minutes  Looking at the example bel...

SQL Server, the window spool operator (and the window functions)

Image
Hi Guys, In the last post we talked about the Lazy Spool operator , today to continue the discussion we will talk about another type of spool: the window spool . We will tell how it works and when the optimizer uses this type of spool. Enjoy the reading!   The window spool Let's say the window spool is both a logical and a physical operator. The optimizer uses this type of spool when dealing with a query that contains a Windows function . I am sure you already know what a windows function is, ...but in case there is someone just entered in the SQL world I gladly remember it .. A window function is simply a function that can operate on a set of rows and return a single aggregated value for each row. For example i can compute an aggregate value without group data. The highlighted part of the string is the window function: SELECT [NAME], [SALARY], MAX ([SALARY]) OVER ( PARTITION BY [NAME] ORDER BY [NAME]) AS MAX_SALARY FROM [EMPLOYEE] order by [NAME], [SALARY] This function return...