FIRST_VALUE Analytic Function in SQL Server - #3

Published: 22 June 2020
on channel: Everyday Be Coding
2,529
23

#SQLServer #FIRSTVALUE #SQLAnalytics #DataAnalysis #TSQL #SQLFunctions #DataScience #Database #SQLQuery #SQLTips #DataEngineering #BigData #Analytics #SQLServer2019 #SQLServer2022 #TechTips #Programming #DataVisualization #BusinessIntelligence #sqlperformance

Playlist -    • CUME_DIST analytic function in SQL Se...  
------------------------------------------------------------------------------------------
CUME_DIST() -    • CUME_DIST analytic function in SQL Se...  
PERCENT_RANK() -    • PERCENT_RANK analytic function in SQL...  
FIRST_VALUE() -    • FIRST_VALUE Analytic Function in SQL ...  
LAST_VALUE() -    • LAST_VALUE Analytic Functions in SQL ...  
LEAD() -    • LED Analytic Function in SQL  - #5 #S...  
LAG() -    • LAG Analytic Function in SQL Server -...  
PERCENTILE_CONT() -    • PERCENTILE_CONT analytic function in ...  
PERCENTILE_DISC() -    • PERCENTILE DISC analytic function in ...  
------------------------------------------------------------------------------------------
QUERY SOLVE -
1. What is analytic functions in SQL Server?
2. What is FIRST_VALUE analytic functions in SQL Server?
3. Syntax of FIRST_VALUE analytic functions?
4. What is partition by clause in SQL Server?
5. What is Order by clause in SQL Server?
6. Default parameters of FIRST_VALUE analytic functions in SQL Server?

FIRST_VALUE()
-------------------------
The first_value function retrieves the first value from the specified column for the records that have been sorted using the ORDER BY clause.
Syntax :
FIRST_VALUE ( [scalar_expression ] )
OVER ( [ partition_by_clause ] order_by_clause [ rows_range_clause ] )

QUERY:
SELECT [Name],
Make,
Model,
Price,
[Type],
FIRST_VALUE (Name) over (PARTITION BY [TYPE] ORDER BY price ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as FIRST_VALUE
--FIRST_VALUE (Name) over (ORDER BY price DESC) as FIRST_VALUE
FROM [DbSample].[dbo].[Bikes]

partition_by_clause divides the result set produced by the FROM clause into partitions to which the function is applied. If not specified, the function treats all rows of the query result set as a single group.

order_by_clause determines the logical order in which the operation is performed. order_by_clause is required.

rows_range_clause further limits the rows within the partition by specifying start and end points.


On this page of the site you can watch the video online FIRST_VALUE Analytic Function in SQL Server - #3 with a duration of hours minute second in good quality, which was uploaded by the user Everyday Be Coding 22 June 2020, share the link with friends and acquaintances, this video has already been watched 2,529 times on youtube and it was liked by 23 viewers. Enjoy your viewing!