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

连续签到领金币

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

with t as(
    select distinct date_format(in_time, '%Y%m') dt, uid, row_number()over(partition by uid order by date_format(in_time, '%Y%m%d')) rk, date_sub(date_format(in_time, '%Y%m%d'), interval row_number()over(partition by uid order by date_format(in_time, '%Y%m%d')) day) f_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'
)

select uid, mon month, sum(case
when cou_day < 3 then cou_day 
when cou_day >= 3 and cou_day <= 6 then cou_day + 2
when cou_day >= 7 and mod(cou_day, 7) < 3 then 15 * (cou_day div 7) + mod(cou_day, 7)
when cou_day >= 7 and mod(cou_day, 7) >= 3 and mod(cou_day, 7) <= 6 then 15 * (cou_day div 7) + mod(cou_day, 7) + 2
end) as coin
from
(select uid, min(dt) mon, count(f_dt) cou_day
from t
group by uid, f_dt) t_day
group by uid, mon
order by uid, mon

全部评论

相关推荐

10-30 10:16
南京大学 Java
龚至诚:给南大✌️跪了
点赞 评论 收藏
分享
面试摇了我吧:啊哈哈面试提前五个小时发,点击不能参加就是放弃
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务