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

连续签到领金币

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

全部评论

相关推荐

03-03 14:54
河南大学 Java
点赞 评论 收藏
分享
焦虑中,不知道怎么办了。。。
西北上单:应该放俩项目合理一些 我是一个业务开发项目 一个AI项目和你这个写的亮点差不多
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# AI面会问哪些问题? #
24476次浏览 480人参与
# 中国电信笔试 #
31011次浏览 283人参与
# 开放七大实习专项,百度暑期实习值得冲吗 #
14048次浏览 209人参与
# 你的实习产出是真实的还是包装的? #
18635次浏览 329人参与
# 如果秋招能重来,我会____ #
96616次浏览 500人参与
# 春招至今,你的战绩如何? #
59439次浏览 535人参与
# 米连集团26产品管培生项目 #
12919次浏览 285人参与
# i人适合做什么工作 #
36838次浏览 124人参与
# 我是面试官,请用一句话让我破防 #
79444次浏览 219人参与
# 哪些公司真双非友好? #
69176次浏览 287人参与
# 找AI工作可以去哪些公司? #
7561次浏览 179人参与
# 从事AI岗需要掌握哪些技术栈? #
7528次浏览 238人参与
# 面试尴尬现场 #
220729次浏览 861人参与
# 投递几十家公司,到现在0offer,大家都一样吗 #
339792次浏览 2163人参与
# 五一之后,实习真的很难找吗? #
102792次浏览 584人参与
# 金三银四,你的春招进行到哪个阶段了? #
21492次浏览 275人参与
# 你做过最难的笔试是哪家公司 #
29736次浏览 182人参与
# 你小时候最想从事什么职业 #
159832次浏览 2072人参与
# 阿里笔试 #
176137次浏览 1300人参与
# 应届生第一份工资要多少合适 #
20463次浏览 84人参与
# 一张图晒出你司的标语 #
3784次浏览 71人参与
# 面试被问期望薪资时该如何回答 #
382445次浏览 2163人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务