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

连续签到领金币

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

with t1
as(
    select
    uid
    ,date(in_time) dt
    from tb_user_log
    where artical_id = 0
    and date(in_time) between '2021-07-07' and '2021-10-31'
    and sign_in = 1
),

t2 as
(
    select
    uid
    ,dt
    ,row_number()over(partition by uid order by dt) rk
    from t1
)

select
uid
,date_format(dt, '%Y%m') month
,sum(coin) coin
from
(
    select
    uid
    ,dt
    ,case when con_sign = 3 then 3
        when con_sign = 0 then 7
    else 1 end as coin
    from(
        select
        uid
        ,dt
        ,date_sub(dt, interval rk day) dt_tmp
        ,row_number()over(partition by uid, date_sub(dt, interval rk day) order by dt) % 7 con_sign
        from t2
    ) a
) b
group by uid, month
order by month, uid

全部评论

相关推荐

03-02 08:18
集美大学 Java
钱嘛数字而已:没有赛事奖项么?另外,项目经历字有点多哈,建议突出一下重点:用的什么技术,解决什么问题,达到什么效果。
大家都开始春招面试了吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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