RANK gives you a rating in your ordered section. Links are assigned the same rank, and the next rating is skipped. So, if you have 3 items in rank 2, the next rank will be considered 5.
DENSE_RANK again gives you a rating in your ordered section, but the ranks are consistent. No ranks are omitted if there are rows with several elements.
As for zeros, it depends on the ORDER BY clause. Here is a simple test script that you can play with to find out what will happen:
with q as ( select 10 deptno, 'rrr' empname, 10000.00 sal from dual union all select 11, 'nnn', 20000.00 from dual union all select 11, 'mmm', 5000.00 from dual union all select 12, 'kkk', 30000 from dual union all select 10, 'fff', 40000 from dual union all select 10, 'ddd', 40000 from dual union all select 10, 'bbb', 50000 from dual union all select 10, 'xxx', null from dual union all select 10, 'ccc', 50000 from dual) select empname, deptno, sal , rank() over (partition by deptno order by sal nulls first) r , dense_rank() over (partition by deptno order by sal nulls first) dr1 , dense_rank() over (partition by deptno order by sal nulls last) dr2 from q; EMP DEPTNO SAL R DR1 DR2
Here is a link to a good explanation and some examples.
DCookie Jun 25 2018-12-12T00: 00Z
source share