The RANK ()
function in SQL Server returns the position of a value within the partition of
a result set, with gaps in the ranking where there are ties.
The DENSE_RANK () function in SQL Server returns the position of a value within the partition of a result set, leaving no gaps in the ranking where there are ties.
Let us understand this difference with an example and then observe the results while using these two functions:
Example for RANK
Keyword: TSQL Interview Questions, SQL Server Interview Questions and Answers,Rank Vs Dense Rank.
The DENSE_RANK () function in SQL Server returns the position of a value within the partition of a result set, leaving no gaps in the ranking where there are ties.
Let us understand this difference with an example and then observe the results while using these two functions:
Example for RANK
Rank
|
Name
|
Age
|
1
|
Ram
|
20
|
2
|
Shayam
|
21
|
2
|
Sohan
|
21
|
4
|
Rohit
|
23
|
4
|
Rohan
|
23
|
4
|
Raj
|
23
|
7
|
XYZ
|
24
|
8
|
YZ
|
25
|
Example
of Dense Rank
Dense Rank
|
Name
|
Age
|
1
|
Ram
|
20
|
2
|
Shayam
|
21
|
2
|
Sohan
|
21
|
3
|
Rohit
|
23
|
3
|
Rohan
|
23
|
3
|
Raj
|
23
|
4
|
XYZ
|
24
|
5
|
YZ
|
25
|
No comments:
Post a Comment