题解 | 连续签到领金币

连续签到领金币

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

with t1 as(
    select 
        uid,
        date(in_time) dt,
        row_number() over(partition by uid,month(date(in_time)) order by date(in_time) asc) rk
    from
        tb_user_log
    where artical_id = 0 and sign_in = 1 and date(in_time) >= '2021-07-07' and
    date(in_time) < '2021-11-01'
)
,t2 as(
    select
        uid,
        date_format(dt,'%Y%m') month,
        case when count(1)%7 <3  then count(1) div 7 *(6+7+2) + count(1)%7
            when count(1)%7 >= 3  then count(1) div 7 *(6+7+2) + count(1)%7+2
            when count(1)%7 = 0 and count(1) div 7 = 0 then 0 
            end coin_temp

    from
        t1
    group by 1,2,date_sub(dt,interval rk day)

)
select 
    uid,
    month,
    sum(coin_temp) coin
from
    t2
group by 1,2

so easy

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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