Skip to Content
-1

how to perform cumulative sum in hana sql

Mar 07 at 10:47 AM

62

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers