题解 | 查询连续登陆的用户

查询连续登陆的用户

https://www.nowcoder.com/practice/9944210610ec417e94140ac09512a3f5

with
    log_tb_new as (
        select
            l.user_id as user_id,
            log_time as log_time,
            lag(l.log_time, 2) over (
                partition by
                    user_id
                order by
                    l.log_time asc
            ) as two_lines_before
        from login_tb l
            inner join register_tb r using (user_id) ##需要注意统计数据必须是在注册表的,所有是内连接
    )
select 
    distinct user_id
from
    log_tb_new
where 
    datediff(log_time,two_lines_before)=2


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务