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

连续签到领金币

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

全部评论

相关推荐

听说改名字就能收到offer哈:Radis写错了兄弟
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务