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

连续签到领金币

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

全部评论

相关推荐

没关系现在见到了、
真的很糟糕:见过国王的offer吗
点赞 评论 收藏
分享
08-19 19:57
石河子大学 C++
企鹅百度字节的孝子:为啥本科只有两年啊
校招求职吐槽
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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