hope you can help me.
I’ve a DB table, lets call it activities
[activities]
[start_time - datetime]
[end_time - datetime]
[name - string]
i need a query which will return me, for each hour of a 24day how many activites were active at that time.
for example:
[time] [usage]
11:00 (11 am) 12
etc…
You may want to use create another table (could be temporary) that holds the numbers 0-23 representing the hours of the day:
Then you should be able to use a query such as the following (using MySQL):
Test case:
Result:
If you don’t want all those 0s, you can use
INNER JOINinstead ofLEFT JOIN. The results we be as follows: