我有一个如下所示的数据集,并不确定从哪里开始。我正在使用Aginity Workbench for Netezza,我想知道何时有互动,看看是否在3个月内有转换。需要扩展到多个客户。
Date Customer Interaction Conversion
1/01/2017 John Smith 1 0
1/02/2017 John Smith 0
1/03/2017 John Smith 0
1/04/2017 John Smith 0
1/05/2017 John Smith 0
1/06/2017 John Smith 1 0
1/07/2017 John Smith 1 0
1/08/2017 John Smith 1
1/09/2017 John Smith 0
1/10/2017 John Smith 0
1/11/2017 John Smith 0
1/12/2017 John Smith 0
理想情况下,输出应如下所示,根据三个月的交互窗口,转换属于一次。因此,如果在后续月份中有任何交互,则将转换归因于3个月窗口的第一个月。还需要标记同月发生的交互和转换。
Date Customer Interaction Conversion 3MonthConversion
1/01/2017 John Smith 1 0 0
1/02/2017 John Smith 0
1/03/2017 John Smith 0
1/04/2017 John Smith 0
1/05/2017 John Smith 0
1/06/2017 John Smith 1 0 1
1/07/2017 John Smith 1 0
1/08/2017 John Smith 1
1/09/2017 John Smith 0
1/10/2017 John Smith 0
1/11/2017 John Smith 0
1/12/2017 John Smith 0
答案 0 :(得分:0)
以下查询应该有效。如果您遇到任何问题,请告诉我
select date,customer, interaction,conversion,
case when interaction=1 and (lead(conversion,1) over (order by date))=1 then 1
when interaction=1 and (lead(conversion,2) over (order by date))=1 then 1
when interaction=1 and (lead(conversion,3) over (order by date))=1 then 1
else 0 end as threeMonthconversion
from test_month