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

连续签到领金币

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

#取商一定要用向下取整floor(),否则会报错!
#时间连续问题,记得要去重
with a as (select 
distinct uid,date(in_time) as dt 
from tb_user_log
where date(in_time) between '2021-07-07' and '2021-10-31' and artical_id=0 and sign_in=1),
b as (
select 
uid,dt,
date_sub(dt,interval row_number() over (partition by uid order by dt) day) flag
from a),
c as (
select 
uid,flag,date_format(dt,'%Y%m') as month,count(*) as cnt
from b 
group by uid,flag,date_format(dt,'%Y%m')
),
d as (
select uid,month,
case when cnt<3 then cnt
    when cnt>=3 and cnt<7 then cnt+2
    when cnt=7 then 7+2+6
    when cnt>7 and cnt%7<3 then cnt%7+floor(cnt/7)*15
    when cnt>7 and cnt%7>=3 and cnt%7<7 then cnt%7+2+floor(cnt/7)*15
    end as coin
from c)

select uid,month,round(sum(coin)) as 'coin'
from d
group by uid,month
order by month,uid

全部评论

相关推荐

计算机类的会考啥啊
投递中国电信等公司10个岗位
点赞 评论 收藏
分享
09-17 11:43
门头沟学院 C++
寄寄寄寄寄寄寄寄
投递腾讯等公司10个岗位
点赞 评论 收藏
分享
08-27 21:03
已编辑
西南石油大学 Java
冷花幽露:大概率是了,京东面试就是这样。我上周一面也是20多分钟,面试官问的很刁钻的问题也答上来了,面完过了几天还是没推进,泡池子,昨天一看挂了。如果一面完第2天没有收到2面邀请,基本上不用抱希望了。如果你的bg是985,面试流程也是和我们一样,20多分钟,唯一区别就是面完他们会很快收到二面邮件,而不像我们泡池子然后挂掉
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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