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

连续签到领金币

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

with t1 as (select uid,date(in_time) dt
from tb_user_log 
where artical_id = 0
and in_time < '2021-11-01'
and in_time >= '2021-07-07'
and sign_in = 1
group by uid,date(in_time)
),
t2 as (select uid,dt,rank() over (partition by uid order by dt ASC) rank_num
from t1
),
t3 as (select uid,dt,rank_num,date_add(dt,interval - rank_num day) rank_dt
from t2)

select uid,replace(substr(dt,1,7),'-','') month,
sum(case when coin_num % 7 = 3 then 3 when coin_num % 7 = 0 then 7 else 1 end) coin
from (select uid,dt,rank() over (partition by uid,rank_dt order by dt) coin_num
from t3) u 
group by uid,replace(substr(dt,1,7),'-','')
order by month,uid ASC

全部评论

相关推荐

昨天 00:11
已编辑
广东工业大学 算法工程师
避雷深圳&nbsp;&nbsp;yidao,试用期&nbsp;6&nbsp;个月。好嘛,试用期还没结束,就直接告诉你尽快找下一家吧,我谢谢您嘞
牛客75408465号:笑死,直属领导和 hr 口径都没统一,各自说了一些离谱的被裁理由,你们能不能认真一点呀,哈哈哈哈哈😅😅😅
点赞 评论 收藏
分享
头像
11-06 10:58
已编辑
门头沟学院 嵌入式工程师
双非25想找富婆不想打工:哦,这该死的伦敦腔,我敢打赌,你简直是个天才,如果我有offer的话,我一定用offer狠狠的打在你的脸上
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务