题解有个不严谨的地方就是,如果用户是近7天内的新用户,并且在7天内不止活跃1次,用这个方法就没办法确定用户是“忠实”还是“新晋”,想在原题解的基础上做一下修改,确保题解的严谨性,没想到意外发现times根本就不用去计算,真是没想到能在确保题解严谨性的同时进一步精简代码,具体如下: select grade ,round(count(*)/(select count(distinct uid) from tb_user_log),2) as ration from (select case when min_gap<7 and max_map>=7 then "忠实用户" when min_gap<7 and max_map<7 then "新晋用户" when min_gap>=7 and min_gap<30 then "沉睡用户" when min_gap>=30 then "流失用户" end as grade, uid from(select uid,min(gap) as min_gap,max(gap) as max_map from(select uid,timestampdiff(day,in_time,(select max(in_time) from tb_user_log)) as gap from tb_user_log) tmp group by uid) base) info group by grade order by ration desc,grade
点赞

相关推荐

10-05 23:02
东北大学 Java
我说句实话啊:那时候看三个月培训班视频,随便做个项目背点八股,都能说3 40w是侮辱价
点赞 评论 收藏
分享
牛客网
牛客企业服务