Tuesday, 6 February 2018

Powerful SQL Function

So today I am posting some code on what are probably the most powerful functions in SQL. Analytical function. I am most familiar with these in Oracle but I think they are mostly the same in SQL server and I have shown the row_number and the lag function. 

The functions allow you to get data from other rows in the data-set without having to join back to the table again. For example look at the lag function below and then the picture of it shown after that. As you can see for each row it has retrieved the price for the preceding date. 

The code:

The Output

No comments:

Post a Comment