cancel
Showing results for 
Search instead for 
Did you mean: 

how to perform cumulative sum in hana sql

former_member383962
Participant
0 Kudos

Hi Experts,

I have to calculate cumulative sum based on condition.

Conditions:

The cumulative sum value should not greater the 20.

|Id| yr_1| yr_2 |
|p1 | 10  |      |
|p2 | 20  |      |
|p3 | 10  |      |

from the above table calculating the cumulative values means we get the following result:

|Id| yr_1| yr_2 | c_value|
|p1 | 10  |      | 10       |
|p2 | 20  |      | 30       |
|p3 | 10  |      | 40       |

but my requirement is the cumulative value should not exceed 20 .

If the value is exceed 20 means I have to skip the current row value and continue with the next value .

And update the skipped value to yr_2 column with the respective id.

my output looks like this as shown as below:

|Id| yr_1 | yr_2 | 
|p1 | 10  |      | 
|p2 | 0   | 20   | 
|p3 | 10  |      | 

Thanks in advance

Accepted Solutions (0)

Answers (0)