题解 | 连续签到领金币

连续签到领金币

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

with t0 as(
select uid,date_format(in_time,'%Y%m%d') as dt ,DATE_FORMAT(in_time,'%Y%m') as month,sign_in from tb_user_log where artical_id=0 and in_time between '2021-07-07' and '2021-11-01' and sign_in!=0
),
t1 as (
select uid,month,count(cnt) as cn from (
select uid,month,dt-rk+sign_in as cnt from(
select uid,month,dt,row_number() over(partition by uid order by dt) as rk ,sign_in from t0 )t) tmp group by 1,2,cnt)

select uid,month,sum(case when cn>=3 and cn<7 then cn+2 when cn>=7 then floor(cn/7)*15+floor(cn%7/3)*5+cn-7*floor(cn/7)-3*floor(cn%7/3) else cn end ) as coin from t1 group by 1,2 order by 2,1


全部评论

相关推荐

12-15 11:27
门头沟学院 Java
哇哇的菜鸡oc:所有人不要理会,就好了,后面他就知道怎么回事了,只能说有的时候市场都是被宰的人搞坏的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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