我想根據他們本來可以完成的活動來計算客戶流失率,而不是按日期流失,這是正常情況。我們有與特定主機連接的事件,在我的示例中,所有事件都由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
任何想法?
「攪動」後會發生什麼?他們攪拌一次還是停止攪動? – gbn
每個人或COUNT個人的標誌是? – gbn
當你流失後,你可以重新復活,然後你可以再次攪動。在我的例子中,鮑勃攪動(即將離開事件3和事件4),但在事件5復活。 – corpat