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

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

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

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

全部评论

相关推荐

湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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