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

连续签到领金币

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

思路:
①如何判断连签:用签到日期-日期排序=连签日期(连签日期一致表明连续签到),对连签日期计数即得到连签天数。
②连签天数以7天一个周期,每个周期里第3天、第7天得3分、7分,其余得1分,用%7进行取余判断。

with tb1 as(
select uid, date(in_time) dt, 
date_sub(date(in_time),interval rank()over(partition by uid order by date(in_time)) day) r
from tb_user_log
where date(in_time) between '2021-07-07' and '2021-10-31' and artical_id=0 and sign_in=1)

select uid, `month`, sum(num)
from(
select uid, date_format(dt,'%Y%m') `month`, 
case when l_dt%7=3 then 3
when l_dt%7=0 then 7
else 1 end as num
from(select uid, dt, count(r)over(partition by uid, r order by dt) l_dt from tb1) tb2
) tb3
group by uid, `month`
order by `month`, uid

全部评论

相关推荐

点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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