Skip to content
Advertisement

SQL – Flag rows till 0 value of each group

I am calculating a running balance and want to flag all rows till 0 value to have ‘MATCHED’ flag else ‘NOT-MATCHED’ flag with respect to account ID.

enter image description here

Here is what I have tried but didn’t got proper result:

Advertisement

Answer

We can use a sub-query to find the last acct_rank which is 0 and then use case to test each row.

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