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

连续签到领金币

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

select uid,concat('2021',m) as "month", sum(coin_m) as "coin"
from (
select uid,count(1),m,case when count(1) >=7 then (floor(count(1)/7)*15 + (case when (count(1)%7)>=3 then count(1)%7+2 else count(1)%7 end))
                           when count(1) >=3 then count(1)+2 else count(1) end "coin_m"
from(

select uid,in_time,m,(day(in_time) - ranking) as "const_d",sign_in
from(

select uid,in_time,lpad(month(in_time),2,0) as "m",row_number()over(partition by uid order by in_time) as "ranking",sign_in
from tb_user_log
where in_time between '2021-07-07 00:00:00' and '2021-10-31 23:59:59' 
and artical_id = 0 and sign_in = 1
)t1   
)t2
group by uid,const_d,m    
)t3     
group by uid,m          
order by month,uid

全部评论

相关推荐

offer多多的六边形战士很无语:看了你的博客,感觉挺不错的,可以把你的访问量和粉丝数在简历里提一下,闪光点(仅个人意见)
点赞 评论 收藏
分享
像好涩一样好学:这公司我也拿过 基本明确周六加班 工资还凑活 另外下次镜头往上点儿
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务