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

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

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
全部评论

相关推荐

如题,字节跳动怎么才能看到自己的面评,找hr说看不到
SoulStar:自己应该看不到,这个是字节比较保密的信息,之前有mentor加我,说他能看到,但是不能给我说,给我说了他可能就要被辞退了
点赞 评论 收藏
分享
小谷围鸡肉卷阿姨:+1,腾子投完一动不动
点赞 评论 收藏
分享
重生2012之我是java程序员:换个稍微正式点的照片吧
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务