1

I have a table, a timetable, with check-in and check-out times of the employees:

ID    Date     Check-in     Check out
1     1-1-2011 11:00        18:00
2     1-1-2011 11:00        19:00
3     1-1-2011 16:00        18:30
4     1-1-2011 17:00        20:00

Now I want to know how many employees are working, every (half) hour. The result I want to see:

Hour  Count
11    2
12    2
13    2
14    2
15    2
16    3
17    3
18    2,5
19    1

Every 'Hour' you must read as 'till the next full hour', ex. 11 -> 11:00 - 12:00

Any ideas?

TJ_
  • 629
  • 6
  • 12

1 Answers1

0

Build an additional table, called Hours, containing the following data:

 h
 00:00
 00:30
 01:00
 ...
 23:30

then, run

Select h as 'hour' ,count(ID) as 'count' from timetable,hours where [Check_in]<=h and h<=[Check_out] group by h
Uri Goren
  • 13,386
  • 6
  • 58
  • 110