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

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

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

with temp as(
    select date(max(in_time)) first_login_time
    from tb_user_log
)
select user_grade,
       round(count(1)/(select count(distinct uid) from tb_user_log),2) ratio
from(
    select uid,
       case when datediff((select * from temp),date(max(in_time)))<7 and datediff((select * from temp),date(min(in_time)))>6 then '忠实用户' 
            when datediff((select * from temp),date(min(in_time)))<7 then '新晋用户'
            when datediff((select * from temp),date(max(in_time)))between 7 and 29 then '沉睡用户'
            when datediff((select * from temp),date(max(in_time)))>29 then '流失用户' end as user_grade
    from tb_user_log 
    group by uid
)t
group by user_grade
order by ratio desc;

全部评论

相关推荐

牛奶配面包:第二个经典博弈题目吧
点赞 评论 收藏
分享
03-23 23:00
黄淮学院 Java
才浅Caiq:老家县城送外卖也5000,要求别这么低
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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