题解 | #牛客每个人最近的登录日期(五)#

牛客每个人最近的登录日期(五)

http://www.nowcoder.com/practice/ea0c56cd700344b590182aad03cc61b8

select e.date,round((h/g),3) as p from
(select date,count(user_id) as g from
(select * from
(select *,rank() over(partition by user_id order by date) as rk from login ) as A
where rk=1) as B
group by date) as e
join
(select c.date,count(c.date) as h from
(select * from
(select *,rank() over(partition by user_id order by date) as rk from login
) as A
where rk<3
)c,
(select * from
(select *,rank() over(partition by user_id order by date) as rk from login
) as b
where rk<3
)d
where c.user_id=d.user_id and datediff(d.date,c.date)=1
group by c.date
) as f on e.date=f.date
union
select distinct date,0 as p
from login where date not in (select c.date as h from
(select * from
(select *,rank() over(partition by user_id order by date) as rk from login
) as A
where rk<3
)c,
(select * from
(select *,rank() over(partition by user_id order by date) as rk from login
) as b
where rk<3
)d
where c.user_id=d.user_id and datediff(d.date,c.date)=1
group by c.date
)
order by date


每个用户的第一天的数据表join对应的第二天的数据牛,简单来说就是第一天与后一天连续的次数

全部评论

相关推荐

头像
04-29 10:53
已编辑
东北大学 自动化类
点赞 评论 收藏
转发
投递网易雷火等公司10个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务