Monday, April 11, 2011

RANK() VS DENSE_RANK() With an Example


The RANK() function in SQL Server returns the position of a value within the partition of a result set, with gaps in the ranking where there are ties.

1    3.00    6118

2    4.00    6192
3    7.00    6404
3    7.00    6405
5    7.50    1848

The DENSE_RANK() function in SQL Server returns the position of a value within the partition of a result set, leaving no gaps in the ranking where there are ties.


 

1    3.00    6118
2    4.00    6192
3    7.00    6404
3    7.00    6405
4    7.50    1848