I'd like to write a query that will calculate the total amount of activity that occurred within each 15 minute interval of the day using only timestamps that correspond to activity start and stop times.
Here is a sample data set:
DATE StartDateTime StopDateTime
2/2/2015 2/2/2015 7:00 2/2/2015 7:25
2/2/2015 2/2/2015 7:20 2/2/2015 7:29
2/2/2015 2/2/2015 7:35 2/2/2015 7:42
2/2/2015 2/2/2015 8:05 2/2/2015 8:14
2/2/2015 2/2/2015 8:16 2/2/2015 8:20
2/2/2015 2/2/2015 8:29 2/2/2015 8:40
2/2/2015 2/2/2015 8:55 2/2/2015 9:25
And this is what I'd like to be able to get:
DATE Interval activityTime(min)
2/2/2015 2/2/2015 7:00 15
2/2/2015 2/2/2015 7:15 19
2/2/2015 2/2/2015 7:30 7
2/2/2015 2/2/2015 7:45 0
2/2/2015 2/2/2015 8:00 9
2/2/2015 2/2/2015 8:15 5
2/2/2015 2/2/2015 8:30 10
2/2/2015 2/2/2015 8:45 5
2/2/2015 2/2/2015 9:00 15
2/2/2015 2/2/2015 9:15 10
I've searched to find a way to organize the data in the way that I need and this is the closest that I've been able to find so far though I haven't been able to get it to work:
Splitting time + duration into intervals in t-sql
I'm pretty new to SQL so any explanation of solutions would be much appreciated. This is also my first post on stackoverflow so please let me know if the data are not in the preferred format or if there any additional questions. Thanks!