I have the data as below, When I apply dense_rank by ordering id column, I am getting rank according to the order of integers but I need to rank as the records are displayed when run a query:
Data from query:
Rid id
8100 161
8101 2
8102 2
8103 2
8104 156
When I apply dense_rank over order by id then I am getting
Rid id rank
8100 161 3
8101 2 1
8102 2 1
8103 2 1
8104 156 2
But my requirement is to get in below way:
Rid id rank
8100 161 1
8101 2 2
8102 2 2
8103 2 2
8104 156 3
Used row_number as well but the result is not as expected, not sure what option would be the better way.
Any help is appreciated.
Thanks
Edit------------------------------
Query used
Select rid, id,dense_rank() over (order by id) row_num
from table