:
Use this "times" table, but with two columns containing 15 minute intervals. From time to time it is 15 minutes, to_times is a second until the next from_times. For example, from 12:30 to 12:44:59.
Now find your worksheet for the person I called "activity" here, with the start_time and end_time columns.
I added values for Alice and Bob in accordance with the original question.
Here is a query from MySQL:
SELECT HOUR(times.from_time) AS 'TIME', count(*) / 4 AS 'HOURS'
FROM times
JOIN activity
ON times.from_time >= activity.start_time AND
times.to_time <= activity.end_time
GROUP BY HOUR(times.from_time)
ORDER BY HOUR(times.from_time)
which gives me this:
TIME HOURS
12 0.7500
13 1.0000
14 1.0000
15 1.5000
16 2.0000
17 1.0000
18 1.0000
19 0.7500
It looks right ...
source
share