题解 | #统计活跃间隔对用户分级结果#

统计活跃间隔对用户分级结果

http://www.nowcoder.com/practice/6765b4a4f260455bae513a60b6eed0af

SELECT t.grade, round( count(t.uid)/(select count(distinct uid) from tb_user_log),2) as cnt FROM( select uid, case when datediff(date((select max(in_time) from tb_user_log)),date(max(in_time)))<=6 and datediff(date((select max(in_time) from tb_user_log)),date(min(in_time)))>6 then "忠实用户" when datediff(date((select max(in_time) from tb_user_log)),date(min(in_time)))<=6 then"新晋用户" when datediff(date((select max(in_time) from tb_user_log)),date(max(in_time))) between 7 and 29 then "沉睡用户" when datediff(date((select max(in_time) from tb_user_log)),date(max(in_time)))>29 then "流失用户" end as grade from tb_user_log group by uid ) as t group by t.grade order by cnt desc

与大佬思路不同的是,我是按照最晚的登录时间当成NOW,每个用户登录的最晚的时间7-29天作为沉睡用户,>29天为流失用户,这样好理解
全部评论

相关推荐

06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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