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

连续签到领金币

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

1.提取uid,日期,和不同uid对应的日期排名,注意筛选条件 2.根据上表将同一UID,且日期连续的进行分组,进行计算,得到每一组的具体硬币情况 3.进行汇总,按照uid和月份分组。

select uid,date_format(dt,"%Y%m") as month,sum(coin)
from
(select uid,date_sub(dt,interval rk-1 day) as first_day,
case dense_rank()over(partition by uid,date_sub(dt,interval rk-1 day) order by dt)%7 when 0 then 7
when 3 then 3 else 1 end as coin,
dt 
from
(select uid,date(in_time) dt,dense_rank()over(partition by uid order by date(in_time)) rk from tb_user_log
where sign_in=1 and artical_id=0 and date(in_time) between "2021-07-07" and "2021-10-31")t1)t2
group by uid,date_format(dt,"%Y%m") 
order by month,uid;
全部评论

相关推荐

刘苏杰:应届生春招面试四五十分钟,最后问有几个offer,但没有谈薪资,是什么情况?焦虑不安
点赞 评论 收藏
分享
03-04 07:14
门头沟学院 C++
后测速成辅导一两个月...:老板:都给工作机会了还想要工资,哪来这么多好事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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