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

连续签到领金币

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

with t1 as(select a.uid, a.dt, a.rank_, dense_rank() over(partition by uid,a.dt-a.rank_ order by date(a.dt)) rank_1
from 
(select uid, date(in_time) dt, dense_rank() over(partition by uid order by date(in_time)) rank_
from tb_user_log
where date(in_time) between '2021-07-07' and '2021-10-31'
and sign_in=1
and artical_id=0)a
),
t2 as(select uid, dt, rank_1, 
case when rank_1%7=3 then 3 when rank_1%7=0 then 7 else 1 end coin
from t1)
select uid, date_format(dt,'%Y%m') month, sum(coin)
from t2
group by uid,month
order by month,uid

  • 连续日期用dense_rank和日期相减得到一个同一个日期,然后在用一次dense_rank得到连续日期的天数
  • 使用case when 得到对应的金币数
  • 第3天得到3金币
  • 第7天得到7金币
  • 注意限制
  • artical_id=0
  • sign_in=1
全部评论

相关推荐

没有offer的呆呆:日常和暑期都投试一试,3月份机会挺多的
点赞 评论 收藏
分享
纸鹰:对他说:“你好,我是百度JAVA。”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务