Skip to content
Advertisement

Get latest record after ordering columns based on sequence

I would like to order my table using two columns in manner of sequence as described:

The current balance to start as the previous balance in next row.

Below is my data

And i want it to be ordered first in below sequence

enter image description here

Then select the top most row as my final result i.e.

Any assistance

Advertisement

Answer

This is a hierarchy, you can see the whole cycle running this query:

But if you want only most parent row just use Tejash’s query or not in or not exists:

If you want to go in other direction through all tree, as described in your question, change connect by clause and take leaf row(s):

dbfiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement