HI,
i am trying to rank a column on the condition that a particular value exists
select * from t
id col2
1 1
2 17
3 1
4 1
5 11
6 1
i want to rank the values of col2 order by ID where col2 = 1.
If col2 value is not 1 then rank column should show 0
in other words, rank would show the progressive occurance of value = 1 in col2 order by ID column
the desired output
id col2 rank
1 1 1
2 17 0
3 1 2
4 1 3
5 11 0
6 1 4
pls tell how to achieve this
create table t
(id number,
col2 number)
/
insert into t values ( 1, 1)
insert into t values (2, 17)
insert into t values (3 , 1)
insert into t values (4 , 1)
insert into t values (5 , 11)
insert into t values (6 , 1)