题解 | #连续签到领金币#自定义函数

连续签到领金币

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

with tmp as(
select uid,date(in_time) dt
from tb_user_log
where artical_id = 0 and sign_in = 1
and date(in_time) between '2021-07-07' and '2021-10-31'
order by dt)

select uid,date_format(dt,'%Y%m') as month,
  sum(case when nums in (3,10,17,24,31) then 3
           when nums in (7,14,21,28) then 7
           else 1
           end)
from(
select 
  uid,
  dt,
  if(@pre=date_sub(dt,interval 1 day),@count := @count+1,@count := 1) as nums,
  @pre:=dt
from tmp as l,
    (select  @pre:= null,@count:=1) as pc)t
group by uid,month
order by uid

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-21 17:16
科大讯飞 算法工程师 28.0k*14.0, 百分之三十是绩效,惯例只发0.9
点赞 评论 收藏
分享
10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
10-13 17:47
门头沟学院 Java
wulala.god:图一那个善我面过,老板网上找的题库面的
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务