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

连续签到领金币

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

全部评论

相关推荐

勇敢大角牛2:项目太基础了。小demo就不要往简历中写了,得分是什么鬼,大作业?。并且项目经历和你的求职意向岗位不匹配,没有体现硬件的亮点。话有点糙,还请谅解
点赞 评论 收藏
分享
球球别再泡了:坏,我单9要了14
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务