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

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

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

select
k.user_grade, round(count(k.uid)/(select count(distinct uid) from tb_user_log),2) ratio
from(
    select
    t.uid, 
    case when t.last_log_gap > 29 then '流失用户'
    when t.last_log_gap > 6 and t.last_log_gap <= 29 then '沉睡用户'
    when t.last_log_gap <= 6 and t.early_log_gap <= 6 then '新晋用户'
    else '忠实用户' end as user_grade
    from(
        select
        uid, datediff((select max(out_time) from tb_user_log), min(in_time)) early_log_gap, datediff((select max(out_time) from tb_user_log), max(out_time)) last_log_gap
        from tb_user_log
        group by uid
    ) t
) k
group by user_grade
order by ratio desc

又是参考大佬的,注意复习

全部评论

相关推荐

04-15 14:28
已编辑
Java
程序员小白条:学院+两段经典项目+技术栈,最大众的简历,纯看运气
点赞 评论 收藏
分享
03-27 01:58
已编辑
西北工业大学 Java
在平静中度过当下:如果这个bg也简历挂的话可能他们现在不缺人了吧,我也是这两天投的,阿里和快手投的岗都是简历秒挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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