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

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

https://www.nowcoder.com/practice/16d41af206cd4066a06a3a0aa585ad3d

select
    round((count(distinct d.user_id))/count(distinct c.user_id) ,3) as p
from
    login c
    left join (
        select
            a.user_id, client_id, date, first_day, second_day
        from
            login a,
            (
                select
                    user_id,
                    min(date) as first_day,
                    date_add(min(date), interval 1 day) as second_day
                from
                    login
                group by
                    user_id
            ) b
        where
            a.user_id = b.user_id
            and a.date = b.second_day
    ) d on c.user_id = d.user_id

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务