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

连续签到领金币

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

全部评论

相关推荐

10-22 12:03
山东大学 Java
程序员小白条:26届一般都得有实习,项目可以随便写的,如果不是开源社区的项目,随便包装,技术栈也是一样,所以本质应该找学历厂,多投投央国企和银行,技术要求稍微低一点的,或者国企控股那种,纯互联网一般都得要干活
应届生简历当中,HR最关...
点赞 评论 收藏
分享
09-29 00:03
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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