DENSE_RANK() is an another window function in SQL Server very similar to
RANK() in SQL Server.The exception is, it does not skip any rank, leaving no gaps between the ranks. Again, we are using the same sampledata used in
ROW_NUMBER() in SQL Server blog post for explaining the difference between RANK and DENSE_RANK.
Syntax for RANK function
DENSE_RANK()OVER(PARTITION BY column_list ORDER BY column_list ASC/DESC)
Step 1: The data is first grouping based on partition column list.
Step 2: As per the order column list the rank is applied on the grouped data from the Step 1.
If you have tie on order column, then the same number will repeat, however, unlike RANK() function it will never skip any rank number in the result set.
Select *,DENSE_RANK()Over(ORDER BY Fees ASC) DenseRank,RANK()Over(Order by Fees ASC) _Rank from SampleData
Hope this post helps you to understand the difference between RANK() and DENSE_RANK() window functions in SQL Server.
Hope you enjoyed this post, share your feedback in comment section. Recommending to go through “Microsoft SQL Server – Beginners Guide” series for more information.
I’d like to grow my readership. If you enjoyed this blog post, please share it with your friends!
Like this:
Like Loading...
Related
One thought on “DENSE_RANK() window function in SQL Server”