計算連續登入次數
SQL連續登入
select distinct tel_no, max(count(1)) over(partition by tel_no)
from (select row_number() over(partition by tel_no, call_result order by call_date_time) sn,
row_number() over(order by tel_no, call_date_time) n,
a.*
from test a) a
where call_result = 'Yes'
group by tel_no, n - sn
select distinct tel_no, max(count(1)) over(partition by tel_no)
from (select row_number() over(partition by tel_no, call_result order by call_date_time) sn,
row_number() over(order by tel_no, call_date_time) n,
a.*
from test a) a
where call_result = 'Yes'
group by tel_no, n - sn
留言
張貼留言