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

连续签到领金币

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

select 
    uid,
    month,
    sum(day_coin)
from(
    select 
        uid,
        month,
        case when cday%7 = 3 then sign_in+2
        when cday%7 = 0 then sign_in+6
        else sign_in end as day_coin
    from(
        select 
            uid,
            sign_in,
            date_format(dt,'%Y%m') as month,
            dense_rank() over (partition by date_sub(dt,interval rk day) order by dt) as cday
        from(
            select 
                distinct uid, #一天签到多次的只保留一次
                sign_in,
                date(in_time) as dt,
                dense_rank() over (partition by uid order by date(in_time)) as rk
            from 
                tb_user_log
            where 
                date(in_time) between '2021-07-07' #坑死了这里写7-01不通过
                and  '2021-10-31'
                and sign_in = 1
                and artical_id= 0
            order by uid) as a) as b) as c
group by uid,month
order by month,uid

全部评论

相关推荐

野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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