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

连续签到领金币

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

with tiaojian as (
select 
uid,
date(in_time) as pday
from tb_user_log
where
artical_id=0
and 
sign_in=1
and 
date(in_time) between "2021-07-07" and "2021-10-31"
group by date(in_time),uid
),tiaojian1 as (
select 
uid,
pday,
dense_rank()over(partition by uid,subdate(pday,pn) order by pday) as pdiff
from(
select 
uid,
pday,
dense_rank()over(partition by uid order by pday) as pn
from tiaojian
) as t 
)

select 
uid,
date_format(pday,"%Y%m"),
sum(case when pdiff%7=3 then 3 
         when pdiff%7=0 then 7 else 1 end) as coin
from tiaojian1
group by uid,date_format(pday,"%Y%m")
order by date_format(pday,"%Y%m") asc,uid

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务