LAST_VALUE() function syntax with an example in SQL Server
Introduction:
In my previous posts we have seen what is Transact-Sql in sql server and What are new top features of T-Sql in server. This is one of the best sql server interview Questions and answers. Watch more ASP.NET, C#.NET, Jquery, Sql Server, HTML5, HTML, CSS, JQUERY UI Interview questions from here.
Description:
·
This function returns the last value in an ordered set of values.
Example:
To find out the last match played in every group
Select MatchBetween,
MatchGroup, Last_Value (MatchBetween) Over (Partition By MatchGroup Order By
MatchGroup) As [Last Match In Group] From MatchTable
Result:
MatchBetween
|
MatchGroup
|
Last Match In Group
|
India
VS Australia
|
Group-A
|
Newzealand
VS Pakistan
|
India
VS Pakistan
|
Group-A
|
Newzealand
VS Pakistan
|
India
VS Newzealand
|
Group-A
|
Newzealand
VS Pakistan
|
Australia
VS Pakistan
|
Group-A
|
Newzealand
VS Pakistan
|
Australia
VS Newzealand
|
Group-A
|
Newzealand
VS Pakistan
|
Newzealand
VS Pakistan
|
Group-A
|
Newzealand
VS Pakistan
|
USA
VS WestIndies
|
Group-B
|
Ireland
VS Bangaladesh
|
USA
VS Ireland
|
Group-B
|
Ireland
VS Bangaladesh
|
USA
VS Bangaladesh
|
Group-B
|
Ireland
VS Bangaladesh
|
WestIndies
VS Ireland
|
Group-B
|
Ireland
VS Bangaladesh
|
WestIndies
VS Bangaladesh
|
Group-B
|
Ireland
VS Bangaladesh
|
Ireland
VS Bangaladesh
|
Group-B
|
Ireland
VS Bangaladesh
|
If you have any queries or suggestions, please feel free to ask in comments section.
Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.