mysql中怎么统计留存率
这期内容当中小编将会给大家带来有关mysql中怎么统计留存率,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
Sql代码
begin
declare i int;
declare numareaId int(10);
declare currentareaId int(10);
SELECT COUNT(areaId),MIN(areaId) INTO @a,@b FROM option_area_info;
SET numareaId=@a;
SET currentareaId=@b;
loop1:WHILE numareaId>0 DO
SET @AID = currentareaId;
SET i=1;
while i<8 do
if exists(select * from statistics_player_l where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day) and areaId=@AID) then
update statistics_player_l set oneDayPlayer=(select ((select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day) and loginTime>=date_add(date_sub(curdate(),interval i day),interval 1 day) and loginTime<date_add(date_sub(curdate(),interval i day),interval 2 day) and areaId=@AID)/(select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day)))*100) where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day);
update statistics_player_l set twoDayPlayer=(select ((select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day) and loginTime>=date_add(date_sub(curdate(),interval i day),interval 2 day) and loginTime<date_add(date_sub(curdate(),interval i day),interval 3 day) and areaId=@AID)/(select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day)))*100) where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day);
update statistics_player_l set threeDayPlayer=(select ((select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day) and loginTime>=date_add(date_sub(curdate(),interval i day),interval 3 day) and loginTime<date_add(date_sub(curdate(),interval i day),interval 4 day) and areaId=@AID)/(select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day)))*100) where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day);
update statistics_player_l set fourDayPlayer=(select ((select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day) and loginTime>=date_add(date_sub(curdate(),interval i day),interval 4 day) and loginTime<date_add(date_sub(curdate(),interval i day),interval 5 day) and areaId=@AID)/(select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day)))*100) where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day);
update statistics_player_l set fiveDayPlayer=(select ((select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day) and loginTime>=date_add(date_sub(curdate(),interval i day),interval 5 day) and loginTime<date_add(date_sub(curdate(),interval i day),interval 6 day) and areaId=@AID)/(select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day)))*100) where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day);
update statistics_player_l set sixDayPlayer=(select ((select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day) and loginTime>=date_add(date_sub(curdate(),interval i day),interval 6 day) and loginTime<date_add(date_sub(curdate(),interval i day),interval 7 day) and areaId=@AID)/(select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day)))*100) where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day);
update statistics_player_l set sevenDayPlayer=(select ((select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day) and loginTime>=date_add(date_sub(curdate(),interval i day),interval 7 day) and loginTime<date_add(date_sub(curdate(),interval i day),interval 8 day) and areaId=@AID)/(select count(distinct playerId) from log_login where registerTime=date_sub(curdate(),interval i day)))*100) where createTime>=date_sub(curdate(),interval i day) and createTime<date_sub(curdate(),interval i-1 day);
end if;
SET i=i+1;
end while;
SET numareaId=numareaId-1;
SET currentareaId=currentareaId+1;
END WHILE loop1;
end
上述就是小编为大家分享的mysql中怎么统计留存率了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341