题解 | #牛客每个人最近的登录日期(三)#
牛客每个人最近的登录日期(三)
https://www.nowcoder.com/practice/16d41af206cd4066a06a3a0aa585ad3d
#分子:login自连接,h1的date和h2的date差一天,h2的date作为后一天,若h2的date不为null,说明后一天有登录,计算h2不为null的user_id个数
# 分母:所有的user_id个数
select
round(
(select count(distinct user_id)
from
(
select h1.user_id,h1.date,h2.date as dt2
from login h1
left join login h2
on h1.user_id=h2.user_id and date_add(h1.date,interval 1 day)=h2.date)h
where dt2 is not null)
/(select count(distinct user_id) from login),
3)
