题解 | #连续签到领金币#

连续签到领金币

https://www.nowcoder.com/practice/aef5adcef574468c82659e8911bb297f

with t1 as (
    select uid,
    date(in_time) as log_day,
    row_number()over(partition by uid order by in_time) as rk
    from tb_user_log
    where artical_id = 0 and sign_in = 1
    and date_format(in_time,'%Y%m%d') between 20210707 and 20211031
    )

select uid,month, sum(daily_coin) as coin
from
(
    select 
uid,month,cdd,
case
when cdd%7 = 3 then 3
when cdd%7 = 0 then 7
else 1
end as daily_coin
from
    (
    select uid, 
date_format(log_day,'%Y%m') as month, 
date_sub(log_day,interval rk day) as initial_day,
row_number()over(partition by date_sub(log_day,interval rk day),uid) as cdd
from t1
     ) t2
) t3
group by 1,2

全部评论

相关推荐

01-26 22:20
已编辑
门头沟学院 Java
Java抽象带篮子:项目很nb了,现在好好准备八股和算法吧,早点找实习,可以看看我的置顶帖子。帖子里写了怎么改简历,怎么包装实习经历,还有2个高质量可速成的项目话术,和我的牛客八股笔记专栏
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务