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

连续签到领金币

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

with
    t2 as (
        select
            uid,
            time,
            time - rank() over (
                partition by
                    uid
                order by
                    time
            ) rk
        from
            (
                select
                    uid,
                    date (in_time) as time
                from
                    tb_user_log
                where
                    artical_id = 0
                    and sign_in = 1
            ) t1
        where
            date (time) between '2021-07-07' and '2021-10-31'
    )
select
    uid,
    month,
    sum(money) as coin
from
    (
        select
            uid,
            left (time + 1 -1, 6) as month,
            (
                case
                    when rk1 = 0 then 7
                    when rk1 = 3 then 3
                    else 1
                end
            ) as money
        from
            (
                select
                    uid,
                    time,
                    row_number() over (
                        partition by
                            uid,
                            rk
                        order by
                            time
                    ) mod 7 as rk1
                from
                    t2
            ) t3
    ) t4
group by
    uid,
    month
order by
    month,
    uid

全部评论

相关推荐

10-05 23:02
东北大学 Java
我说句实话啊:那时候看三个月培训班视频,随便做个项目背点八股,都能说3 40w是侮辱价
点赞 评论 收藏
分享
找不到工作死了算了:没事的,雨英,hr肯主动告知结果已经超越大部分hr了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-26 18:54
说等下个版本吧的发呆爱好者很贪睡:佬最后去了哪家呀
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务