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

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

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

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

全部评论

相关推荐

09-29 17:44
已编辑
蔚来_测(准入职员工)
//鲨鱼辣椒:见不了了我实习了四个月上周再投筛选了一天就给我挂了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务