Assign Rank based on two columns from single row

Database

Assign Rank based on two columns from single row

Hi,

I want to create single rank based on two columns from a single record.

 

I have sample source data like below

Current IDPrevious ID
68
49
84
313
93

 

Trying to derive a rank as below

IDDerived Rank
131
32
93
44
85
66

 

Please help in writing query for the same.


Accepted Solutions
N/A

Re: Assign Rank based on two columns from single row

That's not a rank, it's traversing across a hierarchy.

You need WITH RECURSIVE with a seed Select to find the 1st row (MAX(previous_id)?) and then it's current_id = cte.previous_id.

1 ACCEPTED SOLUTION
1 REPLY
N/A

Re: Assign Rank based on two columns from single row

That's not a rank, it's traversing across a hierarchy.

You need WITH RECURSIVE with a seed Select to find the 1st row (MAX(previous_id)?) and then it's current_id = cte.previous_id.