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

查询连续登陆的用户

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

with a as(
select
    l.user_id as user_id,
    substring(log_time,1,10) as time
from login_tb l
join register_tb r
on l.user_id=r.user_id
),
b as(select distinct * from a),
c as
(
select
    user_id,
    time,
    row_number() over(partition by user_id) as datediff
from b
group by user_id,time
),
d as(
select 
    user_id,
    date_sub(time,interval datediff day) as date,
    count(*) as count
from c
group by user_id,date_sub(time,interval datediff day)
)

select
    user_id
from d
where count >= 3
order by user_id
;

全部评论

相关推荐

求个付费实习岗位:这种就是吃满时代红利又没啥技术水平,只能靠压力学生彰显优越感的老登,别太在意了
点赞 评论 收藏
分享
10-27 02:29
已编辑
门头沟学院 嵌入式工程师
牛客72783561...:简历不是这么写的,你这两个项目只说了用到了什么技术,却没说取得了什么成果,在我看来这就是你自己做的一个demo,没有价值。你为什么不写你电赛国二的那个项目?
点赞 评论 收藏
分享
12-17 11:18
深圳大学 Java
顺丰数科 IT研发 16*14 硕士其他
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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