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

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

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

with a as
(
    select uid,in_time,row_number() over(partition by uid order by in_time) r1,
      row_number() over(partition by uid order by in_time desc) r2,
        datediff(max(in_time) over (order by in_time desc),in_time) cha
        
    from tb_user_log
),
    b as 
(
    select uid,   
    min(case when r1=1 and cha<=6 then 0
         when r1!=1 and r2=1 and cha<=6 then 1
         when r2=1 and cha>=7 and cha<=29 then 2
         when r2=1 and cha>=30 then 3
    end) name1
    from a
    group by uid 
)

select case name1 
when 0 then '新晋用户'
when 1 then '忠实用户'
when 2 then '沉睡用户'
when 3 then '流失用户'
end ,round(count(name1)/(select count(*) from b),2)
from b
group by name1
order by 2 desc
全部评论

相关推荐

11-01 20:03
已编辑
门头沟学院 算法工程师
Amazarashi66:这种也是幸存者偏差了,拿不到这个价的才是大多数
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务