WITH REG AS( SELECT user_id, MIN(date) AS reg_date FROM login GROUP BY user_id) SELECT date, ROUND(IFNULL(LEAD(revisit_total, 1) OVER(ORDER BY date)/reg_total, 0), 3) AS p FROM( SELECT date, SUM(IF(date = reg_date, 1 , 0)) AS reg_total, SUM(IF(DATE_SUB(DATE, INTERVAL 1 DAY) = re...