On the move:

I'm currently moving the following to their own blogs: Unix, HTML for Blogs, Perl & Java.
The links are on the left side.

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.

1 comment:

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

    ReplyDelete