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

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

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

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

全部评论

相关推荐

好消息是活的像个人了,周末可以约会吃饭打游戏了坏消息是钱没了,当初来小红书就是为了钱啊哭笑不得😭
犯困嫌疑人:好事儿啊,取消大小周能有更多自己的时间,周末还能约对象玩,这不美滋滋?
投递小红书等公司6个岗位 > 小红书取消大小周
点赞 评论 收藏
分享
03-19 10:07
已编辑
广东药科大学 golang
Yki_:你倒是进一个面啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务