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

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

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

select
    case
    when timestampdiff(day, last_date, max_date) >= 30  then '流失用户'
    when timestampdiff(day, last_date, max_date) >= 7 then '沉睡用户'
    when timestampdiff(day, first_date, max_date) < 7 then '新晋用户'
    else '忠实用户'
    end as user_grade,
    round(count(*) / max(total), 2) as ratio
from
    (select uid, min(date(in_time)) as first_date, max(date(out_time)) as last_date
    from tb_user_log
    group by uid) as t1
left join
    (select max(date(out_time)) as max_date, count(distinct uid) as total
    from tb_user_log 
    ) as t2 on 1
group by user_grade
order by ratio desc








全部评论

相关推荐

不愿透露姓名的神秘牛友
07-25 17:51
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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