Suggested Videos
Part 112 - Calculate running total in SQL Server 2012
Part 113 - NTILE function in SQL Server
Part 114 - Lead and Lag functions in SQL Server 2012
In this video we will discuss FIRST_VALUE function in SQL Server
FIRST_VALUE function
FIRST_VALUE function example WITHOUT partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the entire table.
FIRST_VALUE function example WITH partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the respective partition.
Part 112 - Calculate running total in SQL Server 2012
Part 113 - NTILE function in SQL Server
Part 114 - Lead and Lag functions in SQL Server 2012
In this video we will discuss FIRST_VALUE function in SQL Server
FIRST_VALUE function
- Introduced in SQL Server 2012
- Retrieves the first value from the specified column
- ORDER BY clause is required
- PARTITION BY clause is optional
FIRST_VALUE function example WITHOUT partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the entire table.
SELECT Name, Gender, Salary,
FIRST_VALUE(Name) OVER (ORDER BY Salary) AS FirstValue
FROM Employees![first_value function example](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbA0tq-us8rOtJu55m9LoZxz5qioxBsQO1S2wRkWuL20_ztatAffs8k2x5Yk5ESceg9YLQc1XHnq70PfxgLehdLgNFyXnMRvugN2fKJl8iyJzxiMU3HV8Y2eR3f3qg3zSFLHwoDOiq5XU/s1600/first_value+function+example.png)
FIRST_VALUE function example WITH partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the respective partition.
SELECT Name, Gender, Salary,
FIRST_VALUE(Name) OVER (PARTITION BY Gender ORDER BY Salary) AS FirstValue
FROM Employees![sql server 2012 first_value function](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjXDlaaugmskdY76OCPYtNYvfmLsPJfy05qHnFiQiP0oRF-G0INidWUuAWejbn3AIp6MYHWogKP4tmIP5W1QOcKBQ0xPmslhqwBFYAhyphenhyphen_4cBTkQkYHaXHUNRAbnssmHtcdvBDrMkVFgfQ/s1600/sql+server+2012+first_value+function.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCgUXVtzkqGbIyKr6tjLAA10w43LqpENiYCOndEUbgLU00GzdJF6rG_QjH-eAiL0asdM8O_h6T6UIWYMhMV0Vl7G5ONW9nOUWqTDmI_esaGYvcMMe_QbH2lFjkv3HCI_buweSMNrU3zm54/s1600/sql+server+tutorial.png)
No comments:
Post a Comment
It would be great if you can help share these free resources