I want to display the count of values when the value gets changed to 0 for the current record.
im not much familier with sql , tried self join but dint worked
see Input records below.
Date, value 2018-12, 0 2018-11, 1 2018-10, 1 2018-09, 1 2018-08, 0 2018-07, 0 2018-06, 1 2018-05, 0 2018-04, 1 2018-03, 0 2018-02, 0 2018-01, 1 output shroud be as below .
Date, value, Count 2018-12, 0 , 3 2018-11, 1 , 2 2018-10, 1 , 1 2018-09, 1 , 0 2018-08, 0 , 0 2018-07, 0 , 2 2018-06, 1 , 1 2018-05, 1 , 0 2018-04, 0 , 0 2018-03, 0 , 0 2018-02, 0 , 1 2018-01, 1 ,null for the first record 2018-12, 0 we need to track when first occurrence of 0 came.once 0 came we need to stop count there.
In this case 0 came on 2018-08, 0 for the first record 2018-12, 0 . so we need to keep count 3 for 2018-12, 0.
For 2018-11, 1 we got 0 after two values so we need to keep 2.
For 2018-08, 0 we got 0 immediately so 0 need to keep.
For 2018-07, 0 we got 0 after two values so 2 need to keep like that.
Im not good at writing sql, please help how to write sql for this scenario.
sumwindow function andleadwindow function