不用子查询,最简洁易懂的代码

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

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

select
     case when  datediff(today,newd)<7 then '新晋用户'
     when datediff(today,dt)<7 then '忠实用户'
    when datediff(today,dt)<30 then '沉睡用户'
    else  '流失用户' end as user_grade,
    round(count(uid)/sm,2) as ratio
from (select uid,max(date(out_time)) as dt,min(date(out_time)) as newd from tb_user_log group by uid) as t1  , (select max(date(out_time)) as today,count(distinct uid) as sm from tb_user_log) as t2 
group by user_grade,today,sm
order by ratio desc

看其他大佬发的题解都复杂一点点,我这个就直接上相对简洁的代码,不做解析了

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-25 17:51
点赞 评论 收藏
分享
07-10 14:08
已编辑
江西农业大学 Java
拒绝无效加班的小学生...:期望3k吗?java这辈子有了
点赞 评论 收藏
分享
快点约我面试吧
投递百度等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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