题解 | #连续签到领金币#
连续签到领金币
http://www.nowcoder.com/practice/aef5adcef574468c82659e8911bb297f
select uid, date_format(dt,"%Y%m") `month`, sum(get_coin_num) coin from(select uid, dt, date_sub(dt,interval rk-1 day) start_date, case(dense_rank() over(partition by uid,date_sub(dt,interval rk-1 day) order by dt))%7 when 3 then 3 when 0 then 7 else 1 end get_coin_num from(select uid, date(in_time) dt, dense_rank() over(partition by uid order by date(in_time)) rk from tb_user_log where artical_id=0 and sign_in=1 and date(in_time) between '2021-07-07' and '2021-10-31')t)t group by uid,date_format(dt,"%Y%m") order by `month`,uid