FIRST_VALUE() function
FIRST_VALUE() function is introduced in SQL Server 2012. FIRST_VALUE() returns first value from the list.
Syntax:- FIRST_VALUE( [scalar_expression] ) OVER ( [ partition_by_clause ] order_by_clause rows_range_clause)
Example:-
FIRST_VALUE() function is introduced in SQL Server 2012. FIRST_VALUE() returns first value from the list.
Syntax:- FIRST_VALUE( [scalar_expression] ) OVER ( [ partition_by_clause ] order_by_clause rows_range_clause)
Example:-
NAME MONTH YEAR AMOUNT ------------------------------------------------- Alok Kumar Singh MAY 2016 50000.48 Tomas Paul MAY 2016 54000.43 Cristomfer Dee MAY 2016 456463.89 Niel Macengi MAY 2016 150021.00 Alok Kumar Singh JUNE 2016 450000.00 Alok Kumar Singh OCTOBER 2016 45.00 SELECT SAL.NAME, SAL.[MONTH], SAL.[YEAR], SAL.AMOUNT, FIRST_VALUE(SAL.AMOUNT) OVER (ORDER BY SAL.AMOUNT) FstValue FROM SALARY SAL OUTPUT:- NAME MONTH YEAR AMOUNT FstValue ------------------------------------------------------------ Alok Kumar Singh OCTOBER 2016 45.00 45.00 Alok Kumar Singh MAY 2016 50000.48 45.00 Tomas Paul MAY 2016 54000.43 45.00 Niel Macengi MAY 2016 150021.00 45.00 Alok Kumar Singh JUNE 2016 450000.00 45.00 Cristomfer Dee MAY 2016 456463.89 45.00
No comments:
Post a Comment
Note: only a member of this blog may post a comment.