sql >> Base de Datos >  >> RDS >> Mysql

Cree una suma ROLLING durante un período de tiempo en mysql

Y una solución más

SELECT r1.date, r1.time_spent, sum(r2.time_spent) AS rolling_week_total
FROM rolling_total AS r1 JOIN rolling_total AS r2
    ON datediff(r1.date, r2.date) BETWEEN 0 AND 7
GROUP BY r1.date
ORDER BY r1.date
LIMIT 8