LAST_VALUE() function syntax with an example in SQL Server

LAST_VALUE() function syntax with an example in SQL Server


·        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.
Share this post :

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.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar