题解 | #连续签到领金币#
连续签到领金币
http://www.nowcoder.com/practice/aef5adcef574468c82659e8911bb297f
select uid,month,sum(c) coin
from(
select uid,month,(case when count(sign)=7 then 15 when count(sign)>=3 then count(sign)+2 else count(sign) end) c
from(
select uid,date_format(in_time,'%Y%m') month,date_sub(date(in_time),
interval (case when row_number()over(partition by uid order by in_time)%7=0 then 7 else row_number()over(partition by uid order by in_time)%7 end) day) sign
from tb_user_log
where sign_in=1 and date(in_time) between '2021-7-7' and '2021-10-31' and artical_id=0
)a
group by uid,month,sign
)b
from(
select uid,month,(case when count(sign)=7 then 15 when count(sign)>=3 then count(sign)+2 else count(sign) end) c
from(
select uid,date_format(in_time,'%Y%m') month,date_sub(date(in_time),
interval (case when row_number()over(partition by uid order by in_time)%7=0 then 7 else row_number()over(partition by uid order by in_time)%7 end) day) sign
from tb_user_log
where sign_in=1 and date(in_time) between '2021-7-7' and '2021-10-31' and artical_id=0
)a
group by uid,month,sign
)b
group by month,uid
order by month,uid


阿里云工作强度 727人发布