select visitor,orders,min(date) as min.date from table group by visitor,orders
这应该是这样的:
visitor orders min.date
A 0 1-Jan
B 0 1-Jan
B 1 4-Jan
A 1 12-Jan
这个表(我们称之为tbl)可以自连接以提供
select A.visitor,datediff(day,purchase.date,first.visit) as days.to.purchase
from (select visitor,min.date as first.visit from tbl where orders=0) A
inner join (select visitor,min.date as purchase.date from tbl where orders=1) B
on A.visitor=B.visitor
现在,用一个外部查询 Package 此查询,以统计具有相同日期差异的访问者:
select days.to.purchase,count(visitors) as visitors from
(select A.visitor,datediff(day,purchase.date,first.visit) as days.to.purchase
from (select visitor,min.date as first.visit from tbl where orders=0) A
inner join (select visitor,min.date as purchase.date from tbl where orders=1) B
on A.visitor=B.visitor
) joined
group by days.to.purchase order by days.to.purchase
希望我没听错。我不确定这是不是正确的解决方案,但你没有给我太多的开始:) 完整的解决方案可以是:
select days.to.purchase,count(visitors) as visitors from
(select A.visitor,datediff(day,purchase.date,first.visit) as days.to.purchase
from
(select visitor,min.date as first.visit from
(select visitor,orders,min(date) as min.date from table group by visitor,orders) tbl where orders=0) A
inner join
(select visitor,min.date as purchase.date from
(select visitor,orders,min(date) as min.date from table group by visitor,orders) tbl where orders=1) B
on A.visitor=B.visitor
) joined
group by days.to.purchase order by days.to.purchase
1条答案
按热度按时间qoefvg9y1#
如果我理解正确的话:你需要做的是找到访客+订单的每个组合的最小日期
这应该是这样的:
这个表(我们称之为tbl)可以自连接以提供
现在,用一个外部查询 Package 此查询,以统计具有相同日期差异的访问者:
希望我没听错。我不确定这是不是正确的解决方案,但你没有给我太多的开始:)
完整的解决方案可以是: