SELECT uid, DATE_FORMAT(dt,'%Y%m') month, sum(day_coin) coin from (SELECT *, DATE_SUB(dt,INTERVAL rn day) dt_tmp, case DENSE_RANK() over(PARTITION BY DATE_SUB(dt,INTERVAL rn day),uid ORDER BY dt )%7 WHEN 3 THEN 3 WHEN 0 THEN 7 ELSE 1 END as day_coin from (SELECT DISTINCT uid, DATE(in_time) dt, DENSE...