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

You can do something like this:
SQL> select * from calendar;
    PERSON M T W T F S S
         1 Y Y N Y Y N N
         2 Y Y Y Y Y N N
SQL> select * from holiday;
    PERSON HOL
         1 12-FEB-10
         2 09-FEB-10
SQL> define start_day=2010-02-01
SQL> define end_day=2010-02-20
SQL> with period as (
  2  select DATE '&start_day' start_date, DATE '&end_day' end_date
  3    from dual),
  4  days as (
  5  select start_date+level-1 day
  6    from dual,period
  7  connect by level <= end_date-start_date+1),
  8  mycal as (
  9  select person, 'monday' day, mon works from calendar union all
10  select person, 'tuesday' day, tue from calendar union all
11  select person, 'wednesday' day, wed from calendar union all
12  select person, 'thursday' day, thu from calendar union all
13  select person, 'friday' day, fri from calendar union all
14  select person, 'saturday' day, sat from calendar union all
15  select person, 'sunday' day, sun from calendar
16  )
17  select person, count(0)
18    from mycal c, days d
19   where c.day = trim(to_char(d.day,'day'))
20     and c.works='Y'
21     and not exists (select 1 from holiday h where h.person=c.person and h.hol=d.day)
22  group by person;
old   2: select DATE '&start_day' start_date, DATE '&end_day' end_date
new   2: select DATE '2010-02-01' start_date, DATE '2010-02-20' end_date
    PERSON   COUNT(0)
         1         11
         2         14The PERIOD view is there only to accept start and end date.
The DAYS view contains all the days of the period
The MYCAL view unpivotes the calendar days returning 7 rows for each person, a row per weekday
Max
http://oracleitalia.wordpress.com

Similar Messages

  • How to go from 150$ per month to 750$ per month in BizSpark?

    Hey,
    I apologize if this is in a wrong forum category but I am new to this.
    As the title explains I just want to know what steps should I do to achieve 750$ per month. I asked some of my friends about it and they told me that it is by doing a multiple accounts or something like that, but I am still not aware of the exact process.
    Thanks in advance,
    ViRuSeS

    hi ViRuSeS,
    Thanks for your posting.
    It seems that every subscription has 150$ per month, they have 5 subscriptions. I recommend you refer to this blog:
    http://blogs.msdn.com/b/niallsblog/archive/2014/08/22/activating-your-5-free-azure-accounts-on-bizspark.aspx
    And you also contact to Azure support team for more details:
    http://www.windowsazure.com/en-us/support/contact/
    Regards,
    Will
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Does the 12 euro per month package include a full version of lightroom and photoshop

    I wonder if the proposed limited package of 12 euro per month (if submission for a whole year) includes the full version of photoshop and lightroom or is it limited in use ? for exemple maximum of ... hours per month of GB per month etc...?

    Hi DJL-photo ,
    Welcome to Adobe Forums
    The Photoshop Photography Program Plan do not have any limitation of Usage , Its a Subscription with a one year committment where in you will be charged on monthly basis .
    How ever if you want to store any files etc , then we have 20 GB space for storage like in Creative Cloud
    Let us know if that helps !
    Thanks
    Garima
    Message was edited by: Garima.J

  • Create sales order in ref to quantity contract automatically once per month

    Hi there.
    Is it possible to create a sales order (ZOR) automatically, for example, once per month, in reference to a quantity contract (CQ) for as long as the contract is valid ?
    So, instead of create manually a subsequent order on the contract let it be done automatically. Once per month or once per week or once per .......
    Each contract needs to create it is own sales order. There are approx. 50contracts.
    Would appreciate your help on this.
    cheers !
    Ed

    We can write a BDC and schedule the program every month in the back ground.
    It needs ABAP and Basis help.
    Reward points
    Regards,
    Anbu

  • Input query with dynamic actual & forecast values by month per year

    Hello,
    I am working on a Input ready query for a forecasting application which shows both actuals and forecast numbers and the user will revise the forecast numbers by month
    Requirement: I want to build a Input query for monthly forecasting for the current year. It will be dynamic rolling of months with actuals & forecast data.
    E.g. My report has 12 months for the current year
    and if run the report in May, the months before May has to show the actuals and the months after May has to show the old forecast data so that the user will revise the numbers again in each month and save the data to the real time cube.
    Jan.Feb.Mar.Apr.May.Jun.Jul.Aug.Sept.Nov.Dec
    Act Act  Act Act Act  Old frcst for the remaining months
      user will revise forecast for these months
    So, i am able to create Input query with all restricted key figures( plan kf has change mode set to change, actual kf are not set change) and calculate key figures and all the logic is done on dynamically moving/rolling the data based on the input month of the year.
    But the problem is that i am using cal kf to dynamically roll months, i was not able to set the change option for the cal kf.
    So, how can i make sure that the dynamically changed plan months will open for entering forecast and the actuals months not to change?
    Do you guys have any better solutions in implementing it?
    I really appreciate it your input....:)
    Thanks,
    Srini

    Hi,
    Please look at the following DOC which may be useful to you and if so please grant me point.
    Regards,
    SUbha'
    Input-Ready Query
    Use
    You use input-ready queries to create applications for manual planning. These can range from simple data entry scenarios to complex planning applications.
    Integration
    You define a query that you want to use for manual planning in the BEx Query Designer (see Defining New Queries).
    In the Web Application Designer or the BEx Analyzer, you can combine the input-ready queries with other queries and planning functions to create complex planning applications.
    Prerequisites
    You can define an input-ready query on any of the following InfoProviders:
    &#9679;     Aggregation levels (see Aggregation Levels)
    &#9679;     MultiProviders that include at least one simple aggregation level
    The aggregation levels are created in the planning modeler; MultiProviders are defined in the modeling functional area of the Data Warehousing Workbench.
    Features
    Definition of an Input-Ready Query
    Once you have defined a query on an InfoProvider, you see the Planning tab page under the Properties of structural components (for example, in key figures or restricted key figures). The options provided there allow you to determine which structural components of an input-ready query are to be input ready at runtime and which are not. With structural components that are not input ready, you can also determine whether these components are viewed as reference data or are just protected against manual entry.
    For the structural components, you also have the following options:
    Input readiness of structural components of a query
    Option
    Description
    Not input ready (reference data)
    If they are being used as reference data, the structural components are not protected by data locks to ensure exclusive access for one user because this data serves as a reference for many users.
    This is the default setting.
    Not input ready (no reference data)
    If you want to protect structural components against manual entries but allow changes by planning functions, you can use locks to protect this data for one particular user. In this way you can ensure that the planning function works with the displayed data only and not with data that has been changed by other users.
    Input ready
    You can also determine whether an input ready query is to be started in change mode or in display mode. You find this property in the Query Properties on the Planning tab page. If there is at least one input-ready query component, the query (as long as it has not been determined otherwise) is started in display mode.
    In BI applications that use input ready queries as data providers, you can enter data manually at runtime. For more information, see Performing Manual Planning and Creation of Planning Applications.
    Example
    You want to create an input-ready query for manual planning for a plan-actual comparison of revenues for a set of products. You want the plan data in a real-time-enabled InfoCube and the actual data in a standard InfoCube.
           1.      Create a MultiProvider that includes the InfoCubes for the plan and actual data.
           2.      Define an aggregation level on the MultiProvider which contains the characteristic Product and the key figure Revenue.
           3.      On the aggregation level, create two restricted key figures Plan Revenue and Actual Revenue. For restriction, choose the characteristic 0INFOPROV and restrict it to the plan or actual InfoCube.
           4.      Add the restricted key figures to the key figure structure. Insert Product into the rows. For Plan Revenue, choose Input Ready for the input-readiness option. For Actual Revenue, choose the option Not Input Ready (Reference Data).
           5.      In the query properties, set the indicator that determines whether the queries are started in display or change mode as required.
    Example of an input-ready query
    Product
    Plan Revenue
    Actual Revenue
    P01
    20
    P02
    30
    If you want to keep actual and plan data in a real-time enabled InfoCube, you do not require a MultiProvider for the task described above. Create an aggregation level on the InfoCube and define the input-ready query for the aggregation level. In the example above, a version characteristic acts as the InfoProvider. Create restricted key figures with the plan or actual version and proceed as in the previous example.

  • When I pre ordered my iphone 6 i was told I was going to get an additional 1 gig of data per month for a year.  It even shows it on the receipt i received with the phone.  When will I see that reflected on my account.  I have had my new phone for a week a

    When I pre ordered my iphone 6 i was told I was going to get an additional 1 gig of data per month for a year.  It even shows it on the receipt i received with the phone.  When will I see that reflected on my account.  I have had my new phone for a week and used tons more data than usual and am hoping that will save me this month.

    concretedonkey, I'm glad you were able to take advantage of this offer when you ordered your new iPhone 6. I can certainly review your account to ensure this was added for you. Please reply to the direct message I have sent you.
    AndreaS_VZW
    Follow us on Twitter @VZWSupport

  • Does RM29.90 per month photography package with photoshop and lightrooms come with Adobe bridge app as well?

    Does RM29.90 per month photography package with photoshop and lightrooms come with Adobe bridge app as well?

    Does RM29.90 per month photography package with photoshop and lightrooms come with Adobe bridge app as well?

  • Help with Sql for Annual Report per month

    Hi, I have been given the task to create an annual report by month that would show company's profits per month and totals in the last column to show which branch had the hightest income.
    Branch||January||February||March||April||May||June....||Total||     
    ABC ||$0.00 ||$0.00 ||$0.00||$0.00||$0.00||$0.00||Total Amt||
    DEF ||$18.01 ||$3.88 ||$18.01||$4.12||$18.01||$3.97||Total Amt||
    Can anyone please help me in giving an idea of how to write sql for this report..? I am building sub-queries for everymonth by giving the dates for Jan/Feb/March..but I think this is not the right way to do this....
    SELECT
    sum(a.commission) December,
    sum(b.commission) November
    FROM
    Select
    c.account_id,
    c.officer,
    c.account_product_class_id,
    sum(c.dp_monthly_premium) Commission
    From
    contract c
    Where
    c.account_id=109 and
    c.status='APPROVED' and
    c.protection_effective between '01-DEC-2009' and '31-DEC-2009'
    Group by
    c.account_id,
    c.officer,
    c.account_product_class_id
    ) a,
    Select
    c.account_id,
    c.officer,
    c.account_product_class_id,
    sum(c.dp_monthly_premium) Commission
    From
    contract c
    Where
    c.account_id=109 and
    c.status='APPROVED' and
    c.protection_effective between '01-NOV-2009' and '30-NOV-2009'
    Group by
    c.account_id,
    c.officer,
    c.account_product_class_id
    ) b
    I always have hight hope from this forum. So please help. Thanks in advance.
    Edited by: Aditi_Seth on Jan 26, 2010 2:29 PM

    You may try a group report on one simple query like:
    Select
    c.account_id, c.officer, to_char(c.protection_effective, 'MM') month
    sum(c.dp_monthly_premium) Commission
    From
    contract c
    Where
    c.status='APPROVED' and .....
    Group by
    c.account_id
    c.officer,
    to_char(c.protection_effective, 'MM')
    break/gropu on account_id, c.officer, to_char(c.protection_effective, 'MM') and total will be automatically calculated by Reports.

  • I bought the 9.99 per month subscription to LR Mobile.  There was a special running that included Photoshop with this subscription.  How do I download and register Photoshop?

    I bought the 9.99 per month subscription to LR Mobile.  There was a special running that included Photoshop with this subscription.  How do I download and register Photoshop?

    If you have the PS+LR bundle, then you should install the Creative Cloud app, first.   One CC is installed, it’ll show all your eligible products on its Apps list, with Install buttons next to the apps you’re licensed to use, and Trial or Try next to the apps you’re not licensed to use.
    The CC app is the first thing on the Adobe Products page.  It is a desktop app, not tablet app. 
    https://www.adobe.com/downloads.html

  • Help with cloud photoshop per month

    For years I have all my products with original photoshop and recently lightroom now I can not upgrade only per month whu ?? for me is more expensive in thsis concept, for yeras I had been loyalty to adobe with original items. What's the benefict to do in this way.
    Regards
    Luis

    No acabo de entender lo que quieres decir Luis, has estado comprando licencias cada uno o dos años y ahora cuando es un modelo de subscripción te gustaría hacerlo mes a mes? Se supone que pretendes utilizar un mes los programas y otro no?
    La oferta actual de Photoshop y Lightroom es bastante atractiva economicamente, a la larga podemos pensar que sale igual o más caro (?), pero también dispondrás de versiones mejoradas con más posibilidades y funciones (eso prometen y parece que van cumpliendo). Si tu trabajo no crees que se beneficie de la evolución del programa, puedes quedarte en la CS6, aunque quizás llegará un momento en que cambios en sistemas operativos limiten su utilización o compatibilidad.
    Como bien dice Claudio, para un mero observador, Adobe quiere aumentar sus beneficios, garantizarse un flujo constante de ingresos, no uno puntual, fluctuante, cada 12-18 meses, y asegurarse o fidelizar -absolutamente- a sus usuarios/clientes.

  • I have lightroom.  My photos are stored on an external disk drive with a backup disk.  With iCloud, will all of my photos go to the cloud?  Will I still need the external drives? Is the $9.99 per month for just one year or for always?

    I am an amateur photographer and have lightroom.  My photos are stored on an external disk drive with a backup disk.  With iCloud, will all of my photos go to the cloud?  Will I still need the external drives? Is the $9.99 per month for just one year or for always? 

    If the iTunes database files are on that drive, launch iTunes with the Shift key(Windows) or Option key(Mac OS X) held down, select Choose Library, and navigate to it. The computer may need to be authorized to play protected content, and if the library contains rented movies, those won't play.
    If not, import the content to an iTunes library.
    (100371)

  • I need help installing Lightroom 5.  I tried the trial and it does not have an uninstall feature.  Thus, I'm trying to activate with my new $9.99 per month subscription and it simply will not work. Very frustrating you already took my money and no results

    I need help installing Lightroom 5.  I tried the trial and it does not have an uninstall feature.  Thus, I'm trying to activate with my new $9.99 per month subscription and it simply will not work. Very frustrating you already took my money and no results, and very difficult to get help.

    Lightroom Trial uninstall wrote:
    Very frustrating you already took my money and no results, and very difficult to get help.
    Just for clarity, "we" haven't taken your money - this is a user-to-user forum, and you're not talking to Adobe.
    Like Rob I'm a Windows user, and - like him - I thought "uninstalling" on Macs was simply a case of trashing the application. Google would seem to concur.
    Not really a Lightroom/Adobe issue, then?

  • My iPhone 4 crashes very often (3-4 times per day) and sometimes (2-3 times per month) all my apps disappear and I have to restore them with iTunes. I downloaded all the system updatings and I also tried to restore my device, but I still have this issue

    My iPhone 4 crashes very often (3-4 times per day) and sometimes (2-3 times per month) all my apps disappear and I have to restore them with iTunes. I downloaded all the system updatings and I also tried to restore my device, but I still have this issue

    If you haven't already, try restoring your iPhone as a new device, not from a backup, and with only the apps Apple includes. Then see if the problems persist. It's possible that a corrupted file on the iPhone is causing the problems, and that could perhaps be coming back onto the iPhone if you're restoring using a backup. Problems with an app could also be causing problems. If the problems persist after restoring the iPhone as "new", then you almost certainly have a defective iPhone and will need to contact Apple for servicing.
    If the problems go away after restoring the iPhone as "new", then you can start putting your other apps back on and see if the problems reappear; if they do, you probably have a badly-coded app.
    Regards.

  • Hi, I have a Powermac with Mavericks and an iPhone 5S. I just recently switched from Verizon with unlimited downloads to limited of 500mb per month. I just purchased a Powerlink Outdoor Plus which is supposed to increase the network range for over 1 mile

    Hi, I have a Powermac with Mavericks and a recently purchased iPhone 5S. I just  switched from Verizon with unlimited downloads to limited of 500mb per month, so I purchased a Powerlink Outdoor Plus which is supposed to increase the network range for over 1 mile. I am still getting the same distance range with my iPhone with the Verizon router. I was wondering if I need to make adjustments in the Network Settings. Does anyone know about this particular subject?
    Thanks,
    Kevin

    Okay, I'll admit I don't know much about your configuration. A standard cellular package for a cellphone means you get your signal from a tower somewhere.  It won't have anything to do with a router which will be a WiFi connection from a router.  If you're talking about that, the Powerlink appears to be a directional antenna.  You should get better transmission/reception in the direction it is pointed, but likely worse in other directions than if you were using an omnidirectional antenna.  I presume you have it all hooked up correctly so the router is actually using the Powerlink antenna.
    By the way, those distance ratings are always exaggerated.  Maybe you'd get 1 mile if there was only dry air between you and the antenna and no trees, buildings, etc., and that would probably be just barely getting a signal.  You should see improvement but don't go to a coffeeshop 1 mile away in a city and expect to see your router.  We have a directional antenna on the roof of our house that looks like a satellite dish and I barely pick up the wireless service node a block away (with apartment buildings in between).  Thre may also be a difference between using it to send a signal and receiving a signal.  You might even need two, one at each end, to get 1 mile.

  • Right now I am working in a temporary site format. I am hosting the website on my own computer. How to I take it from a temporary site to a live site? Do I need to upgrade my service with abode and does this cost more per month?

    Right now I am working in a temporary site format. I am hosting the website on my own computer. How to I take it from a temporary site to a live site? Do I need to upgrade my service with abode and does this cost more per month?

    Hi Traci,
    To push the site live, you will need to:
    Publish a trial site on BC (File menu> Publish)
    Then, go to the admin dashboard of your site and the launch the site live by paying for it or redeeming a free site.
    Add domain to the site
    Change name-servers at domain registrar
    For steps 3 and 4, kindly refer to the following link:
    http://docs.businesscatalyst.com/user-manual#!/site-settings/site-domains/change-the-domai n-name-of-your-site
    The following link might also be helpful:
    Launching a Muse Site | Adobe Muse CC
    Regards,
    Sonam

Maybe you are looking for

  • IPod refuses to play a certain song which plays fine in iTunes

    20gb iPod colour refuses to play a song I downloaded from the iTunes store, "Through the Fire and Flames" by Dragonforce. It plays perfectly in iTunes, but whenever I want to play it on my iPod, it automatically skips to the next song, despite not ha

  • How to change the Rescue email?

    How to change the rescue email?

  • JVM Encoding

    Hello, My problem has to do with JVM encoding. I have the following error: Error:th encoding of your Java VM is different from the OpenCms encoding Java VM file encoding: Cp1253 OpenCms encoding: ISO-8859-1 How can I change the Java VM encoding to mu

  • [SOLVED] Web Email Clients are unable to connect to IMAP

    I have an quite weird problem. I have an local IMAP Server here on a test machine. Kmail can receive emails and everything works fine. Every other Email Client (Evolution, Squirrelmail, Roundcube) can not Receive emails, even with the identical setti

  • Need to collect Arabic responses

    Hello, I need to collect responses in Arabic Unicode. Is there a way i can remove the validation for unsupported characters in the HTML form. I am able to input them manualy, export to excel and to pdf and also can collect them via PDF form. But it i