Does anyone have a good approach for generating a daily resume from a table containing time intervals given by start and end dates (where the zero-stop facility goes on indefinitely)?
The best way to describe the problem is with an example. Imagine database tracking schedules for employees in a restaurant where employees are often hired and fired. Sometimes employees may return and re-hire.
For a table with one row for each employee, as shown below:
position,name,start,end
bottle washer,Fred,1/2/2013,1/5/2013
bottle washer,Barney,1/4/2013,1/7/2013
bottle washer,Betty,1/10/2013,
bottle washer,Wilma,1/12/2013,1/13/2013
cook,Bilbo,1/1/2013,1/3/2013
cook,Frodo,1/5/2013,1/8/2013
cook,Bilbo,1/7/2013
I am looking for a query that creates one row for each day / position, providing the staffing level for that day, for example:
position,date,staffing
bottle washer,1/1/2013,0
bottle washer,1/2/2013,1
bottle washer,1/3/2013,1
bottle washer,1/4/2013,2
bottle washer,1/5/2013,2
bottle washer,1/6/2013,1
bottle washer,1/7/2013,1
bottle washer,1/8/2013,0
bottle washer,1/9/2013,0
bottle washer,1/10/2013,1
bottle washer,1/11/2013,1
bottle washer,1/12/2013,2
bottle washer,1/13/2013,2
bottle washer,1/14/2013,1
bottle washer,1/15/2013,1
cook,1/1/2013,1
cook,1/2/2013,1
cook,1/3/2013,1
cook,1/4/2013,0
cook,1/5/2013,1
cook,1/6/2013,1
cook,1/7/2013,2
cook,1/8/2013,2
cook,1/9/2013,1
cook,1/10/2013,1
cook,1/11/2013,1
cook,1/12/2013,1
cook,1/13/2013,1
cook,1/14/2013,1
cook,1/15/2013,1
, , , SQL-. , . Oracle, .
?