Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9193

Re: how to calculate the cumulative sum  with certain interval in SAP HANA

$
0
0

Hi Henrique,

 


the SQL,

 

select id, date, col1, ((lag(col1, 1, 0) over (partition by ID orderby  date) +col1)*col1) as cummulative_sum from Table

 

Give the result as mentioned below, which is not the requirement I am looking for . I have also given the correct values of my requirement below,

 

ID          Date                           column 1          Cumulative sum     correct ***_sum

1          9-14-2014 14:05:00          1                    1                              1

1          9-14-2014 14:22:00          1                    2                              2

1          9-14-2014 14:25:00          1                   2                              3

1          9-14-2014 14:37:00          0                    0                              0

1          9-14-2014 15:02:00          0                    0                              0

1          9-14-2014 15:12:00          1                    1                              1

1          9-14-2014 15:18:00          1                    2                              2

1          9-14-2014 15:21:00          1                    2                              3

2          9-14-2014 13:22:00          0                    0                              0

2          9-14-2014 14:25:00          1                    1                              1

2          9-14-2014 14:32:00          1                    2                              2

2          9-14-2014 14:45:00          0                    0                              0

2          9-14-2014 14:59:00          0                    0                              0

 

 

 

we need start the cumulative sum for every time the column 1 has consecutive 1s


Viewing all articles
Browse latest Browse all 9193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>