Monday, April 18, 2011

RANK vs DENSE_RANK

If you're not familiar with how RANK works, you may want to check out my previous post by clicking here.

This post shows the difference between RANK and DENSE_RANK.
Select DeptNo
     , Sal
     ,             RANK() OVER (Partition By DeptNo
                                    Order By Sal  )
       Rank
     ,       DENSE_RANK() OVER (Partition By DeptNo
                                    Order By Sal  )
       Dense
  From Emp
 Where DeptNo <> 20
 Order By DeptNo, Rank;
 
Here you can see that RANK leaves a gap after a tie and DENSE_RANK does not.

2 comments:

  1. Simple and concise explanation. Basically rank doesn't use consecutive numbers. Also a good post here:
    dense_rank and rank differences

    ReplyDelete
  2. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. rank tracker

    ReplyDelete