Created
December 1, 2014 06:32
-
-
Save beginor/259ff6b6bbcbbb57546f to your computer and use it in GitHub Desktop.
SQL Server 2012 TSQL New Function LAG, LEAD, FIRST_VALUE And LAST_VALUE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT [Name] | |
| ,[Subject] | |
| ,[Score] | |
| ,LAG(Score, 1, 0) Over (Partition By Name Order By Subject) As [LagValue] | |
| ,LEAD(Score, 1, 0) Over (Partition By Name Order By Subject) As [LeadValue] | |
| ,FIRST_VALUE(Score) Over (Partition By Name Order By Subject) As [FirstValue] | |
| ,LAST_VALUE(Score) Over (Partition By Name Order By Subject) As [LastValue] | |
| FROM [Test].[dbo].[Score] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment