Along with accumulating window aggregates, Microsoft added eight new window functions with SQL Server 2012. Four of the functions, which I’ll call offset functions in this book, are my favorite T-SQL functions, and they are LAG, LEAD, FIRST_VALUE, and LAST_VALUE. These functions let you include any columns from other rows in your results without a self-join and with fantastic performance.
In this chapter, you will learn how to use LAG ...