题解 | #连续签到领金币#
连续签到领金币
https://www.nowcoder.com/practice/aef5adcef574468c82659e8911bb297f
# 思路:1.根据uid分组日期排序,使用登录日期-排序得到的日期(如果是连续登录日期相同),2.根据日期,uid分组登录日期排序得到的顺序为连续登录天数 3.算金币 整除7 余数为0 为7 余数为3 为3 其余为1 select uid,date_format(time1,'%Y%m') month,sum(coin) from( select *, case when row_number() over(partition by uid,r1 order by time1)%7 = 0 then 7 when row_number() over(partition by uid,r1 order by time1)%7 = 3 then 3 else 1 end coin from( select distinct uid,date(in_time) time1, row_number() over(partition by uid order by date(in_time)) r, date(in_time)-row_number() over(partition by uid order by date(in_time)) r1 from tb_user_log where date(in_time) between '2021-07-07' and '2021-10-31' and artical_id=0 and sign_in=1) t1 ) t2 group by uid,date_format(time1,'%Y%m') order by month ,uid
思路:1.根据uid分组日期排序,使用登录日期减排序得到的日期用来判断连续(如果是连续登录日期相同),2.根据日期,uid分组登录日期排序得到的顺序为连续登录天数 3.算金币 整除7 余数为0 为7 余数为3 为3 其余为1