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

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

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

with a as (
select
    uid,
    (select date(max(out_time)) from tb_user_log) as max_time,
    date(min(in_time)) as zhuce_date, #最远一天
    date(max(in_time)) as huoyue_date  #最近一天
from
    tb_user_log
group by
    uid
),
b as (
select
    uid,
    datediff(max_time, huoyue_date) as last_diff,
    datediff(max_time, zhuce_date) as first_diff
from
    a
),
c as (
select
    uid,
    case
    when first_diff <= 6 then '新晋用户'
    when last_diff <= 6 then '忠实用户'
    when last_diff > 6 and last_diff < 30 then '沉睡用户'
    else '流失用户'
    end as user_grade
from
    b
)
select
    user_grade,
    round(count(*)/(select count(*) from c), 2) as ratio
from
    c
group by
    user_grade
order by
    ratio desc

其实只用找注册日期与现在的diff还有最近活跃日期的diff然后筛选就行了,思路是简单的,但是那个筛选条件折磨了我半个小时...

全部评论

相关推荐

01-02 20:08
马鞍山学院 Java
27届学院本誓死冲击...:实习经历最好写上做了什么项目,负责什么业务,否则有点假
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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