Mysql
 sql >> Database >  >> RDS >> Mysql

Crea una somma ROLLING per un periodo di tempo in mysql

E un'altra soluzione

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