Unlike row_number() function, rank() and dense_rank() may produce duplicate ranks.
1. The data
select num from TBL_TEST order by num;
NUM
----------
1
1
2
2
2
3
4
4
5
2. rank() may have gaps.
select num, rank() over(order by num) as rnk from TBL_TEST order by num;
NUM RNK
---------- ----------
1 1
1 1
2 3
2 3
2 3
3 6
4 7
4 7
5 9
3. dense_ran() does not have gap in ranks.
select num, dense_rank() over(order by num) as rnk from TBL_TEST order by num;
NUM RNK
---------- ----------1 1
1 1
2 2
2 2
2 2
3 3
4 4
4 4
5 5
No comments:
Post a Comment