Skip to content
Advertisement

Oracle PL/SQL SUM OVER( ) starting from certain row

I have a table who looks like this:

I want to achieve the following:

When Pam_A=B, sum the current Value_1 and its preceding row value and keep that value increasing accordding the next value in Value_1

Any ideas for achieve this cumulative sum?

Advertisement

Answer

First of all you need to mark all rows that you want to count. You can do it like this:

Results:

Then you can aggregate only rows that have flag=’Y’:

Results:

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