A query with workingdays per month per persons per period
Can anyone help me on the way in building a difficult SQL query?
I work with Oracle SQL. It is intended to calculate over a certain period, to find the working days for each month for each person.
I have a working query for calculate the number of days for 1 months minus holidays
Select count (*) NUM_WORK_DAYS
From (
Select to_date ('01-01-2010 ',' dd-mm-yyyy ') + ROWNUM-1 as day
From all_objects
Where ROWNUM <to_number (to_char (last_day ('01-01-2010 '), DD')) + 1)
Where to_number (to_char (day, 'd')) between 1 and 5
And not exists (select NULL
From HOLIDAY
Where Holiday.hol=day)
There is a datetable with the following structure where I can get the periods:
DATES
YEAR | MONTH | WEEK | SD
2010 | 201002 | 201006 | 09/02/2010
All required months are present
It is intended that the user give a beginning and a end time specify.
I have a table of workingdays per person named
CALENDAR
CAL | MON | TUE | WED | THU | FRI | SAT | SUN
Person | Y | Y | N | Y | Y | N | N
And a table of holidays
HOLIDAY
CAL | HOL
Person | 01/01/2010
How can I combine the query for working days and build a query that returns for multiple people over multiple months the number of workingdays per month? I will ask the user to give a beginning period and a end period
I am aware that I ask a lot of your time, but I can not imagine the solution myself. Many thanks in advance
Gr,
Els