select uid,month,sum(gold) as coin from (select uid,date_format(dt,'%Y%m') as month, case mod(rank() over(partition by uid ,start order by dt ),7) when 3 then 3 when 0 then 7 else 1 end as gold from (select uid,date_sub(dt,interval rk-1 day) start ,dt from (select distinct uid,date(in_time) as ...