逻辑清晰

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

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


with t as 
(
    select uid,max(date(in_time))over(partition by uid) as max_part_time,
               min(date(in_time))over(partition by uid) as min_part_time,
               date_add(max(date(out_time))over(),interval -6 day) as 7_time,
               date_add(max(date(out_time))over(),interval -29 day) as 29_time,
               (select count(distinct uid) from tb_user_log) as total_num
    from tb_user_log
)
select user_grade,round(count(1)/total_num,2) as ratio
from 
    (select distinct uid ,'忠实用户' as user_grade,total_num
    from t
    where min_part_time<7_time and max_part_time>=7_time
    union ALL
    select distinct uid,'新晋用户' as user_grade,total_num
    from t
    where min_part_time>=7_time
    union all
    select distinct uid,'沉睡用户' as user_grade,total_num
    from t 
    where max_part_time<7_time and max_part_time >=29_time
    union ALL
    select distinct uid,'流失用户' as user_grade,total_num
    from t
    where max_part_time<29_time
    ) t1
group by user_grade
order by ratio desc

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 11:47
点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
我的简历长这样
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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