I have a query that returns DateTime Spans an employee has worked for a day, what week of the year that time relates to and the date of the spans. It works really well, but I want to calculate a running total by day for each day in a particular week.
Currently, my query looks like this:
SELECT A.*
FROM (
SELECT WeekNumber, SUM(NumberOfSecondsWorked) AS NumberOfSecondsWorkedInDay, MIN(FromTime) AS StartOfDay, MAX(ToTime) AS EndOfDay, (SELECT WeeklyTotal = SUM(NumberOfSecondsWorked) FROM #temp AS T2 WHERE T2.WeekNumber = T1.WeekNumber) AS WeeklyTotal
FROM #temp AS T1 GROUP BY DayMonth, WeekNumber) A
And returns this:
The issue I'm having is I would like the Weekly total to be summed by Row for each week, so the data would look like the following:
Where the weekly total sums up for each row. Can anyone tell me what I'm doing wrong in my query?