Friday, April 5, 2013

Ranking Function in Sql

There are four types of ranking function in sql server:

Lets take an example to explain this, First i will create a table called EmpDataDetails and then will insert some record into it.

Types of ranking function:

1.Row_Number:
It assigns rank sequentially. We can also use ranking according to partition.using partition we can break up the results into partitions as per the column selected in partition by. See below Example :


2. Rank : 
if the two values are same both gets the same rank. Then the following rank is skipped.



3. Dense Rank:
Its Behaves the Same as the Rank Function but the following rank is not skipped.



4. NTILE:

Divides into groups as per the Number specified in the NTile Function. if specified 2 it will divide into 2 groups.


2 comments: