I have a table with columns date and time_spent. I want to find for each date D the sum of the values of \'time_spent\' for the period of time : (D
date
time_spent
Here is another solution
SELECT r1.date, r1.time_spent, ( SELECT SUM(time_spent) FROM rolling_total AS r2 WHERE datediff(r1.date, r2.date) BETWEEN 0 AND 7 ) AS rolling_week_total FROM rolling_total AS r1 ORDER BY r1.date LIMIT 8