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