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

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

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

with tmp
as(
    select
    uid
    ,date(min(in_time)) first_date
    ,date(max(in_time)) last_date
    ,(select date(max(in_time)) from tb_user_log) today
    from tb_user_log
    group by uid
)

select
grade
,round(count(distinct uid) / (select count(distinct uid) from tb_user_log), 2) ratio
from
(
    select
    uid 
    ,case when datediff(today, first_date) <= 6 then '新晋用户'
        when datediff(today, first_date) > 6 and datediff(today, last_date) <= 6 then '忠实用户'
        when datediff(today, first_date) > 6 and datediff(today, last_date) >= 30 then '流失用户'
        when datediff(today, first_date) > 6 and datediff(today, last_date) > 6 then '沉睡用户'
        else '其他'
        end grade
    from tmp
)  t

group by grade

全部评论

相关推荐

牛客62533758...:华为不卡双非,而是卡院校hhhh
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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