|
select tel_no,max(r2) r2 from
(
select t.*,
decode(call_result,prv,1,next,1,null) r1,
case
when call_result = prv and call_result != next then
rn - nvl(max(case when call_result != '01' then rn end) over(partition by tel_no order by call_date_time),
min(case when prv is null then rn end) over(partition by tel_no order by call_date_time) - 1)
end as r2
from
(
select t.*,
rownum rn,
lag(call_result,1,null) over(partition by tel_no order by call_date_time) prv,
lead(call_result,1,null) over(partition by tel_no order by call_date_time) next
from test t
) t
) t group by tel_no |
|