What is Dense Rank Function in SQL Server ?Dense Rank Function is Used for provide the Rank of Rows on the basis of any Column value either for Ascending Order or in Descending order.For Example the table given below
if we want to provide the Rank of Salary so we use DenseRank function here as shown in Query
select Salary,DENSE_RANK() over(order by Salary Desc) as SalaryCount
from tbl_Employee_Test
Result of above Query is Given in the below Image
In the Above figure Salary is order by Descending and after that we use DENSERANK function for provide the rank to rows as 8000 is the highest Salary Provides the Rank 1 . Here we use SalaryCount as a Column Name which is the Rank of Salary.
30000 is the Second Highest Salary so here rank is 2 like that Rank for 23000 is 3 and so on.
No comments:
Post a Comment