I have a dataset where i need to check for next 7 consecutive dates if value is 0 then we will put all the in between value as 0 if the values in between are not 0 for 7 days then we will mark all value as 1.
eg:
Dataset
Days Values
12/21/2006 1
12/22/2006 1
12/23/2006 1
12/24/2006 1
12/25/2006 0
12/26/2006 1
12/27/2006 0
12/28/2006 0
12/29/2006 1
12/30/2006 1
12/31/2006 0
1/1/2007 0
1/2/2007 0
1/3/2007 0
1/4/2007 0
1/5/2007 0
1/6/2007 0
1/7/2007 1
1/8/2007 1
Expected Result
Day Values NewVal
12/21/2006 1 1
12/22/2006 1 1
12/23/2006 1 1
12/24/2006 1 1
12/25/2006 0 1
12/26/2006 1 1
12/27/2006 0 1
12/28/2006 0 1
12/29/2006 1 1
12/30/2006 1 1
12/31/2006 0 0
1/1/2007 0 0
1/2/2007 0 0
1/3/2007 0 0
1/4/2007 0 0
1/5/2007 0 0
1/6/2007 0 0
1/7/2007 1 1
1/8/2007 1 1
I have already tried using lead to check the 7 days data but not able to get the consecutive 7 days zero part.In my code whenever it is getting a zero in 7 days offset it is making the value as 0 which is not what i want .
My query is
select *, LEAD(Values,7,0) over (order by gas_dte) as nextval
from temp