I have data in Microsoft SQL Server 2008 that I need to SUM. The catch is I need to group the sums by a 24 hour period. The 24 hour period is from 3:00pm one day to 3:00pm the next day.
For Example
DateExited, Value
1/1/2012 15:00, 5
1/1/2012 15:04, 6
1/1/2012 17:00, 7
1/2/2012 00:00, -5
1/2/2012 09:00, 10
1/2/2012 15:00, 31
The sum of that should be 54. I have the following query but that groups everything from midnight to midnight instead of 3:00 pm to 3:00 pm
SELECT dateadd(day,datediff(day,0, dateadd(hh, 0, DateExited) ),0) As SummaryDate, SUM(Value) as s1
FROM Test
where DateExited BETWEEN dateadd(year,datediff(year,0,GETDATE()),0) AND GetDate()
GROUP BY dateadd(day,datediff(day,0, dateadd(hh, 0, DateExited) ),0)
ORDER BY SummaryDate
You could add minus 15 hours, and then cast the result to date:
Giving you a
group bylike: