This would work for all cases
select DEPT_ID, SALARY,
(select count(*)+1 from emp r where r.SALARY>o.SALARY and r.dept_id=o.dept_id) **rank**,
(select count(distinct SALARY )+1 from emp r where r.SALARY>o.SALARY and r.dept_id=o.dept_id) *d_rank*,
(select count(*)+1 from (select x.*,rownum rn from ( select emp.* from emp order by DEPT_ID asc,salary desc ) x) r where r.rn<o.rn and r.dept_id=o.dept_id) **rownumm**
from (select x.*,rownum rn from ( select emp.* from emp order by DEPT_ID asc,salary desc ) x) o
order by DEPT_ID,salary desc;
for rank:- calculated using (count of (values less than current rows)+1
for dense rank:- same as rank (count distinct value less than current rows)+1
row_number:- create the nested query by generating rownum for each row which will be distinct for all rows. Now on top of that do the same logic as rank
(count of values greater than previous rownum (rownum of select subquery))+1