I need to display a New Sequence column value based on the Score 1 or 0.
MonthlyDate Score New Sequence
----------- ------ ----------
2019-08-01 1 0
2019-08-02 0 1
2019-08-03 0 2
2019-08-04 0 3
2019-08-05 1 0
2019-08-06 0 1
2019-08-07 0 2
2019-08-08 0 3
I am trying to achieve on of the calculation in my project based on the new sequence value.
I have tried sum(score) over (Order By Date rows unbounded preceding)
Case when Score = 1
THEN 0
ELSE (CASE WHEN LAG(Score) OVER (ORDER BY MonthlyDate) = 0
THEN 1
ELSE (SUM(Score) over (Order by MonthlyDate rows unbounded preceding))
END)
END as NewSequence
SUM(SCORE)?Scoreis 0. The SUM of a bunch of zeros will be zero.