I have the following table
I need to arrange them in order of their seniority. Their are two ways to do this. In the first case we use the RANK() function
select empid, empname, age, RANK() over (order by age desc) as Rank 
from [dbo].[Employee]

select empid, empname, age, DENSE_RANK() over (order by age desc) as DenseRank 
from [dbo].[Employee]


If we notice the difference, the first result set doesn't have rank 4. The reason if to people have the same rank, DENSE_RANK() gives the next immediate rank whereas RANK() doesn't. Hence Jack has a rank of 4 via DENSE_RANK() but 5 via RANK().


Petterjohn said...

The seller managed tasks well throughout the timeline.
Interactive design firms were so pleased that they brought the developer on to figure within their core team.

Mark Waji said...

Hmm!! This blog is really cool, I’m so lucky that I have reached here and got this awesome information.
web design firm

Southeast addiction said...

Your blog is extremely brilliant especially the quality content is really appreciable.
UX design firms