SQL

执行顺序:from-on-join-where-group by-with-having-select-distinct-order by-limit
一、用SQL计算留存率
#用户行为信息表 userinfo
1.计算次日留存用户数
create table c as(select a.用户id,a.登陆时间 as a_t,b.登陆时间 as b_t
from 用户行为信息表 as a
left join 用户行为信息表 as b
on a.用户id = b.用户id
where a.应用名称= '相机';)

select *,timestampdiff(day,a_t,b_t)
as day_interval
from c;

select a_t,count(distinct 用户id) as 活跃用户数,
count(distinct case when 时间间隔=1 then 用户id else null end) as 次日留存数,
count(distinct case when 时间间隔=1 then 用户id else null end)/ count(distinct 用户id) as 次日留存率,
count(distinct case when 时间间隔=3 then 用户id else null end) as 三日留存数,
count(distinct case when 时间间隔=3 then 用户id else null end)/ count(distinct 用户id) as 三日留存率,
count(distinct case when 时间间隔=7 then 用户id else null end) as 七日留存数,
count(distinct case when 时间间隔=7 then 用户id else null end)/ count(distinct 用户id) as 七日留存率
from
(select *,timestampdiff(day,a_t,b_t) as 时间间隔
from
(select a.用户id,a.登陆时间 as a_t,b.登陆时间 as b_t
from 用户行为信息表 as a
left join 用户行为信息表 as b
on a.用户id = b.用户id
where a.应用名称= '相机') as c
) as d
group by a_t;

全部评论

相关推荐

合适才能收到offe...:项目岗是什么岗?我看你有段好像跟策划运营相关,如果找运营的话第三段经历写详细点儿。 个人建议是把自我评价删了换成专业技能放在工作经验上或者下面。学生会那个也可以删,把第一个包装成店铺运营,写4-6给点。第三个也是写4-6个点。注意工作内容➕部分数据。 投递的时候BOS招呼用语改一下,换成我有xx工作经验,熟练掌握xx技能样式,也可以简历截图然后直接发送。
点赞 评论 收藏
分享
优秀的大熊猫在okr...:多益:此贼,必有同谋,按律,该当连坐!
你不能接受的企业文化有哪...
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务