Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Rank function help needed

User_W037XJul 17 2022 — edited Jul 17 2022

Screen Shot 2022-07-16 at 5.20.06 PM.pngFor every value in ColA: We need to sort ColB and ColC, then assign a Rank value as shown in the picture.
There is an additional logic here, After we sort ColB and ColC, If the value in ColC is lower than the above below value, then we need to reset the Rank value to 1.

with tab(colA,colB,colC) as (
select x, 1, 10 from dual union all
select x, 2, 12 from dual union all
select x, 3, 14 from dual union all
select x, 4, 111 from dual union all
select x, 5, 120 from dual union all
select x, 6, 150 from dual union all
select x, 7, 0 from dual union all
select x, 8, 1 from dual union all
select x, 9, 2 from dual union all
select y, 1, 11 from dual union all
select y, 2, 12 from dual union all
select y, 3, 13 from dual union all
select y, 4, 1 from dual union all
select y, 5, 3 from dual union all
select y, 6, 4 from dual union all
select y, 7, 5 from dual union all
)

This post has been answered by mathguy on Jul 17 2022
Jump to Answer
Comments
Post Details
Added on Jul 17 2022
11 comments
255 views