Rank()
Rank function will generates a unique number to each distinct row, but it leaves a gap between the groups.
Dense_Rank()
Dense_Rank function is similar to Rank with only difference, this will not leave gaps between groups.
Rank function will generates a unique number to each distinct row, but it leaves a gap between the groups.
Dense_Rank()
Dense_Rank function is similar to Rank with only difference, this will not leave gaps between groups.
DECLARE @Table TABLE ( column varchar(2) ) INSERT INTO @Table (column) VALUES ('A'),('A'),('A'),('B'),('B'),('C'),('C'); SELECT Col_Value, Rank() OVER (ORDER BY column) AS 'Rank', DENSE_RANK() OVER (ORDER BY Col_Value) AS 'DENSE_RANK' FROM @Table;
Column | RANK | DENSE_RANK |
A | 1 | 1 |
A | 1 | 1 |
A | 1 | 1 |
B | 4 | 2 |
B | 4 | 2 |
C | 6 | 3 |
C | 6 | 3 |
0 comments:
Post a Comment