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

连续签到领金币

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

select 
b.uid,
date_format(b.in_time,'%Y%m'),
sum(b.day_num)
from
(
select
a.uid,
a.in_time,
row_number() over(partition by a.uid,a.dt_tmp),
case when row_number() over(partition by a.uid,a.dt_tmp)%7=0 then 7
 when row_number() over(partition by a.uid,a.dt_tmp)%7=3 then 3
 else 1 end as day_num
from
(
select 
uid,
date(in_time) in_time,
row_number() over(partition by uid order by date(in_time)) rn,
date_sub(date(in_time),interval 
row_number() over(partition by uid order by date(in_time)) day) dt_tmp
from tb_user_log
where artical_id=0 and sign_in=1 
and date(in_time)>='2021-07-07' and date(in_time)<='2021-10-31'
) a
) b
group by b.uid,date_format(b.in_time,'%Y%m')
order by date_format(b.in_time,'%Y%m'),b.uid

全部评论

相关推荐

昨天 22:34
已编辑
重庆邮电大学 Java
快手 客户端开发 (n+5)k*16 公积金12
点赞 评论 收藏
分享
孤寡孤寡的牛牛很热情:为什么我2本9硕投了很多,都是简历或者挂,难道那个恶心人的测评真的得认真做吗
点赞 评论 收藏
分享
把球:这个听过,你加了就会发现是字节的hr
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务