나는 그들이 할 수있는 활동을 기반으로 고객의 이탈을 계산하려고 시도하고 있으며, 이는 정상적인 날짜 인 이탈로 반대합니다. 우리는 특정 호스트에 연결된 이벤트를 가지고 있습니다. 예를 들어 모든 이벤트는 Alice가 호스팅하지만 다른 호스트 일 수 있습니다.공백 채우기, 이벤트 기반
특정 이벤트를 따르는 모든 사람들은 카테고리 (신규, 활성, 변경 및 부활)에 배치되어야합니다.
신규 : 처음 특정 사람이 특정 호스트의 이벤트를 수행합니다.
활성 : 다시 따르십시오 (특정 호스트의 마지막 이벤트도 따라했습니다).
휘젓다 : 추종자는 따라 할 기회가 있었지만하지 않았습니다.
부활 됨 : 추종자가 이전에 추적 한 호스트를 따라하기 시작했습니다.
declare @events table (event varchar(50), host varchar(50), date date)
declare @eventFollows table (event varchar(50), follower varchar(50))
insert into @events values ('e_1', 'Alice', GETDATE())
insert into @events values ('e_2', 'Alice', GETDATE())
insert into @events values ('e_3', 'Alice', GETDATE())
insert into @events values ('e_4', 'Alice', GETDATE())
insert into @events values ('e_5', 'Alice', GETDATE())
insert into @eventFollows values ('e_1', 'Bob') --new
insert into @eventFollows values ('e_2', 'Bob') --active
--Bob churned
insert into @eventFollows values ('e_4', 'Megan') --new
insert into @eventFollows values ('e_5', 'Bob') --resurrected
insert into @eventFollows values ('e_5', 'Megan') --active
select * from @events
select * from @eventFollows
예상되는 결과는 내가 다음과 같은의 질의 시작이
select 'e_1', 1 as New, 0 as resurrected, 0 as active, 0 as churned --First time Bob follows Alice event
union all
select 'e_2', 0 as New, 0 as resurrected, 1 as active, 0 as churned --Bob follows the next event that Alice host (considered as Active)
union all
select 'e_3', 0 as New, 0 as resurrected, 0 as active, 1 as churned --Bob churns since he does not follow the next event
union all
select 'e_4', 1 as New, 0 as resurrected, 0 as active, 0 as churned --First time Megan follows Alice event
union all
select 'e_5', 0 as New, 1 as resurrected, 1 as active, 0 as churned --Second time (active) for Megan and Bob is resurrected
같은 것을해야하지만, 문제는 내가 추종자하지 않았다 모든 이벤트를하지 않는다는 것입니다 따라 가라.
select a.event, follower, date,
LAG (a.event,1) over (partition by a.host, ma.follower order by date) as lag,
LEAD (a.event,1) over (partition by a.host, ma.follower order by date) as lead,
LAG (a.event,1) over (partition by a.host order by date) as lagP,
LEAD (a.event,1) over (partition by a.host order by date) as leadP
from @events a left join @eventFollows ma on ma.event = a.event order by host, follower, date
아이디어가 있으십니까?
"churned"이후에는 어떻게됩니까? 그들은 한 번 휘젓다거나 휘젓다? – gbn
깃발은 1 인당 또는 몇 명입니까? – gbn
휘젓다가 다시 부활하면 다시 휘젓다 다. 내 예에서 Bob은 (이벤트 3과 이벤트 4를 제외하고) 이벤트 5에서 부활하지만, 이벤트 5에서 부활합니다. – corpat