I have a data set which is based on a timestamp.
Date Value
07-Jul-15 12:05:00 1
07-Jul-15 12:10:00 1
07-Jul-15 12:
Hi i have tried with below code it's displaying results as expected
with cte
as
(
select Rownum rn,a.* from table a
)
select date1 as start_time,endtime, (endtime-date1)*24*60 as period
from
(
select date1,value,case
when
value=1 then
lead(date1) over (order by date1)
else null
end
as endtime
from
(
select date1,value from cte where cte.rn=1
union all
select a.date1,a.value from cte a
join
cte b
on
a.rn=b.rn+1
and( (a.value=1 and b.value=0) or (a.value=0 and b.value=1))
) order by date1) where value=1