Saturday, July 4, 2015

Ranking Functions

The RANK function sequentially numbers a record set, but when two rows have the same order by value then they get the same ranking. The ranking value still gets incremented when two rows have the same order by value, so that when a new ranking order by value is encountered the ranking value on that new row will be 1 more than the number of proceeding rows.
Ex: 1,2,2,4

The DENSE_RANK function is similar to the RANK function, although this function doesn’t produce gaps in the ranking numbers. Instead this function sequentially ranks each unique ORDER BY value. With the DENSE_RANK function each row either has the same ranking as the preceding row, or has a ranking 1 greater than the prior row. 
Ex: 1,2,2,3

 The NTILE function is used to break up a record set into a specific number of groups. The NTILE function just evenly divides your record set into the number of groups the NTILE function requests. By using the NTILE function each record in a group is give the same ranking. The NTILE function is very useful if you only want to return a specific grouping of records.

No comments:

Post a Comment