Follow Me : https://www.youtube.com/c/SauravAgarwal
view.
○ WITH CHECK OPTION has to have a WHERE clause.
21. What is a RANKING function and what are the four RANKING functions?
Ranking functions are used to give some ranking numbers to each row in a dataset based on some
ranking functionality.
Every ranking function creates a derived column which has integer value.
Different types of RANKING function:
ROW_NUMBER(): assigns an unique number based on the ordering starting with 1. Ties will be
given different ranking positions.
RANK(): assigns an unique rank based on value. When the set of ties ends, the next ranking position
will consider how many tied values exist and then assign the next value a new ranking with
consideration the number of those previous ties. This will make the ranking position skip placement.
position numbers based on how many of the same values occurred (ranking not sequential).
DENSE_RANK(): same as rank, however it will maintain its consecutive order nature regardless of
ties in values; meaning if five records have a tie in the values, the next ranking will begin with the
next
ranking position.
Syntax:
() OVER(condition for ordering) -- always have to have an OVER clause
Ex:
SELECT SalesOrderID, SalesPersonID,
TotalDue,
ROW_NUMBER() OVER(ORDER BY TotalDue), RANK() OVER(ORDER BY TotalDue),
DENSE_RANK() OVER(ORDER BY TotalDue) FROM Sales.SalesOrderHeader
■ NTILE(n): Distributes the rows in an ordered partition into a specified number of groups.
Do'stlaringiz bilan baham: