Calculate the period that a contractor has worked

Guys I have the following query, which gives me the time, a particular contractor held various positions. I need to get the total duration (in days) a particular contractor has worked. If the periods are overlap then these time periods should be calculated only once.

There may be breaks in between that should not be counted... As a result, my query below does not work.

WITH Contractor_Working_Period AS

(SELECT 'Type1' ability, TO_DATE (21 January 1960 ', ' dd/mm/yyyy') valid_from, TO_DATE (' 06 / 02/1985 ', ' dd/mm/yyyy') valid_to OF DOUBLE UNION ALL)

SELECT "Type4" ability, TO_DATE (25 January 2015 ', ' dd/mm/yyyy') valid_from, TO_DATE (December 31, 2015 ', ' dd/mm/yyyy') OF DOUBLE UNION ALL valid_to

SELECT 'Type2' ability, TO_DATE (February 25, 1999 ', ' dd/mm/yyyy') valid_from, TO_DATE (December 25, 2010 ', ' dd/mm/yyyy') OF DOUBLE UNION ALL valid_to

SELECT 'Type3' ability, TO_DATE (February 25, 1980 ', ' dd/mm/yyyy') valid_from, TO_DATE (December 25, 1989 ', ' dd/mm/yyyy') FROM DUAL valid_to)

SELECT

Start_date min (t.valid_from),

Max (t.valid_to) end_date,

Max (t.valid_to) - MIN (t.valid_from) period

OF Contractor_Working_Period t.

Thank you

Napster

Check this box...

WITH Contractor_Working_Period AS

(SELECT 'Type1' ability, TO_DATE (21 January 1960 ', ' dd/mm/yyyy') valid_from, TO_DATE (' 06 / 02/1985 ', ' dd/mm/yyyy') valid_to OF DOUBLE UNION ALL)

SELECT "Type4" ability, TO_DATE (25 January 2015 ', ' dd/mm/yyyy') valid_from, TO_DATE (December 31, 2015 ', ' dd/mm/yyyy') OF DOUBLE UNION ALL valid_to

SELECT 'Type2' ability, TO_DATE (February 25, 1999 ', ' dd/mm/yyyy') valid_from, TO_DATE (December 25, 2010 ', ' dd/mm/yyyy') OF DOUBLE UNION ALL valid_to

SELECT 'Type3' ability, TO_DATE (February 25, 1980 ', ' dd/mm/yyyy') valid_from, TO_DATE (December 25, 1989 ', ' dd/mm/yyyy') FROM DUAL valid_to)

SELECT SUM (CASE WHEN ld_val<= valid_to="" then="">

Of ANOTHER valid_to

END-valid_from) sum_val

Of

(Ability to SELECT,

valid_from,

valid_to,

Lead (valid_from) OVER(ORDER BY valid_from,valid_to) ld_val

OF Contractor_Working_Period

);

OUTPUT:-

========

15591

Thank you

Ann

Tags: Database

Similar Questions

  • How to calculate the periods that overlap between two or more given the date range?

    Hi all

    If there are several durations then how we can calculate the period of time that overlap between these times.

    For example: for 3 time periods. 03/12/2015-16/08/2015, 05/01/2015 to 31/07/2015 and the 06/09/2015 to 30/11/2015, how the overlap period can be calculated?

    There are many potential unknowns in your question.  For example, you want to count any overlap at all?  If two dates overlap, what matters?  Overlap - each of them?

    In any case, here is a solution that counts how many periods are overlapping in any point in time...  She, of course, using temporal logic.  You can then use ValueAt(), WhenLast(), WhenNext(), etc. as appropriate.

    Assume that your model has a child entity called 'the period' with name 'all time periods' relationship and basic attributes 'start date of the period of time' and 'date of end of period of time'.

    In your example:

    an entity should have the time period start date = 03/12/2015 and the date of end of period of time = 16/08/2015

    another entity might have the time period start date = 01/05/2015 and the date of end of period of time = 31/07/2015

    another entity might have the time period start date = 06/09/2015 and the date of end of period of time = 30/11/2015

    To find the number of overlapping over time, we want to count or entities that have an active period, so the rule is perhaps the sum:

    the number of overlapping = the number of all the periods for which it is true that the time period is active

    How do we know a time is active?  This is the time logic comes in.  He is active on or after the start date or no later than the end date:

    the time period is active if

    TemporalOnOrAfter (the date of beginning of period of time) and

    TemporalOnOrBefore (date of end of period of time)

    That's all.  Now, you can perform a temporal visualization of the 'number of overlapping' and you'll see it rise and fall over time.  As a reference, he said that the number of overlapping = 3.0 from 06/09/2015 across 31/07/2015.

    I hope this helps.  You can use the same model to count periods of time functions, but you end up having to use the most logical date.  You of course can count the total number of entities and compare this number of overlap over time to see if they overlap, but I digress...

  • Firefox does not open, but is rather the error message "Unable to read the configuration file." He has worked in the past, but not now.

    Firefox does not open, but is rather the error message "Unable to read the configuration file." He has worked in the past, but not now.

    I REINSTALL 10 TIMES SO DON'T TELL ME THAT!
    I'm piss because I need firefox work again, so I can finish my reseaching in 5 days.


  • Impossible to buy the kit of the student that my account has not been linked to the right country wherever I live, does anyone know if it is possible to change the country, the account is linked to?

    Impossible to buy the kit of the student that my account has not been linked to the right country wherever I live, does anyone know if it is possible to change the country, the account is linked to?

    Your ID, Adobe, payment details and you buy Adobe store must be attached to the same country.

    For tax reasons, it is not possible to change the country associated with an existing Adobe ID.

    To work around the problem, you can create a new Adobe ID to the e-mail address associated with your current Adobe ID.

    Please see this document for instructions: change the country associated with your Adobe ID

    You can see answers to other frequently asked questions creative cloud here:

    Forum FAQ Creative_Cloud

    Concerning

    Megha Rawat

  • After subscription and downloading and installing Acrobat DC, I can open it, but when I try to use one of the tools, I get the message that my trial has expired

    After subscription and downloading and installing Acrobat DC, I can open it, but when I try to use one of the tools, I get the message that my trial has expired.

    Can someone help me?

    Hello

    It is a problem of Activation, please follow the instructions at the link below, it should help solve the problem:

    Connect and disconnect activate Cloud Creative applications

    Applications creative Cloud back in test mode after an update until 2015 for CC

    Let us know if that helps.

    Kind regards

    Bani

  • Trying to connect to Acrobat Connect Pro and the message that your account has expired.

    Trying to connect to Acrobat Connect Pro and the message that your account has expired.

    Hello

    The duration of your account must have expired. You can contact the Adobe Connect Support to extend the life of your account.

    Thank you

    Sameer Puri

  • applesyncnotifer has stopped working unable to locate the component that this application has failed to start because corefoundation.dll was not found. Re-install the app

    Original title: applesyncnotifer has stopped working

    pop-up that said, apple syncnotifer.exe cannot locate the component.  This application has failed to start because corefoundation.dll was not found. Re - install the app may fix the problem.

    Hello

    It's all part of itunes

    Uninstall and reinstall itunes

    Follow the information from apple to the link below

    Remove and reinstall iTunes, QuickTime, and other software components for Windows Vista or Windows 7

    http://support.Apple.com/kb/HT1923

    and or ask for their support of itunes

    http://www.Apple.com/support/iTunes/

    Also try the discussions of apple itunes

    http://discussions.Apple.com/category.jspa?categoryID=149

  • I said that I have to install Chrome to place an order at Walmart. What should the Chrome that Firefox does not work?

    I have placed several orders of Wal-Mart before today using Firefox without any problems. But today, nothing but problems. I tried for more than 4 hours, get this order to cross. I told cat line of Walmart and told me that I have to install Chrome to place an order. They don't answer when I asked if Walmart belonging to Chrome.

    I deleted the cookies and cache and restarted but none of this has worked. While Chrome has that Firefox does not work? I tried Chrome before and he hated and had a devil of a time he get off my computer. I don't want to go there again.

    I have attached a copy of the message that I get seems to indicate that it is a problem within Wal-Mart, but I said that it was with my browser.

    I have a laptop Toshiba Satellite running Windows 7 Ultimate 64 bit and using Firefox 40.0.3.

    Any suggestions would be greatly appreciated. Thank you.

    Thanks for your reply. I just figured out the problem.

    All started when I tried to pay my order at 13:00 this afternoon. I am persistent and don't give up easily. Five hours later, I found an error in their programming, which allowed me to add an item to my shopping cart that was a purchase in store only. But then when I went to pay for it, he became confused and wouldn't let me order but didn't tell me why.

    I solved by moving all items in the basket to saved for later and then add one at a time, trying to get to the car after each addition. It took a while because there are 20 items. He had the same problem when I added the item in the store to the cart and tried to pay for it. So I deleted and purchased on Ebay.

    Now I know probably as much if not more than any of their populations of the Chat line that can only be read on a book script.

    It's a relief that I don't have to use Chrome. I really like Firefox and would not change.

  • Wireless printer connects to the laptop, even though she has worked in the past.

    My printer HP Officejet 6700 Premium connects to my laptop HP Pavilion 15, although he has worked in the past. Other computers around the House connect to the printer and print documents without any problems. When I go to print from Microsoft Word, it says my printer as offline.

    I tried to remove the printer from my devices and printers list (so that I could try to reconnect the printer), but he is not leaving the list after clicking "remove hardware".

    Could someone help me please you troubleshooting? I really need to be able to resume printing my documents for the school.

    Thank you!

    Hi @OfTheFalls

    I'd love to help you reconnect your 6700 printer and computer.

    I suggest using the HP print and Scan doctor first of all, it can solve many printing and scanning errors, network or USB problems, driver problems and conflicts of port connection. Click here to download and run the print and Scan Doctor >www.hp.com/go/tools

    If this does not resolve the problem, after back and let me know if there are all the symbols except the Green checkmarks and what they are next of course. The key is not always easy to identify the key and check mart are in the green circle.

    • If you see only the Green checkmarks ( ), the tool did not find any problem.
  • just installed firefox 8.01 and display is invisible in the my vista screen enlarger. has worked in firefox 3.6. What should I do?

    There is a magnifying glass program in vista, designed for those who have poor eyesight. you move the cursor over the portion of the screen that you want to read and it is displayed in a box at the top of the screen that is larger than the specified size. but in ff8.01 he sees through the window of firefox and displays the vista boot screen so make viable firefox under the microscope. Although the page appears correctly writing is to small to read. It worked well for ff3.6 and fine in google chrome, but the same thing happens in IE9

    Try turning off hardware acceleration.

    • Tools > Options > advanced > General > Browsing: "use hardware acceleration when available.
  • Muse of the reports that my trial has expired, but reports that he is paid and up to date

    I have Adobe Muse CC on my Mac.  When I log into my account, my Muse subscription is paid.  When I opened the Muse CC on my Mac, I get an error that my trial has expired.

    I'm not sure how to get the two to sync so I can continue to use my Muse.

    Any ideas?  24/7 chat support has not been available for more than 36 hours.

    Thank you

    Cliff

    Hello

    Please try to uninstall Muse > disconnect from creative cloud > reconnect and install Muse.

    I hope that this should fix the problem. If still not corrected if please click the link below to Chat and call option with Technical Support.

    Contact the customer service

    Incase chat is not available you can call the number provided telephone support in your region.

    Concerning

    Vivek

  • You try to reset iPad mini, but it keeps saying incorrect password, the password that I use has never been changed, is there a default one?

    You try to reset ipad mini, but it keeps saying incorrect password, I have not changed my password so can't understand why it says incorrect sound, is it a defect or something?

    If you did not, then someone else (who also knew the access code).   Or there is a kind of corruption of the aircraft at low altitude.  Article in support of Apple on the forgotten passwords This usually medium-sized States a reset of the device and a backup restore - anything on the device that is not already been saved will be lost.

  • On startup, I get the messages that applications have stopped working. One of them is (2nd message) IE3SH application has stopped working. How can I fix it?

    Start-up applications to receive messages from windows that have stopped working. One of them is IE3SH application has stopped working. How can I fix it?

    Hi 9gonz9,

    Welcome to the Microsoft Answers site!

    You get this error message when you start the desktop computer?

    You can check if the complete startup items are checked in the msconfig utility.

    1. open System Configuration by clicking Start , clicking Control Panel, clicking system and security, clicking Administrative Tools, and then double-click the System Configuration.

    If you are prompted for an administrator password or a confirmation, type the password or provide confirmation.

    2. click the Startup tab and check if all the items are archived there.

    You can also run a bag of security for your computer and check if this solves the problem.

    http://www.Microsoft.com/Security_Essentials/

    If the problem persists, turn the computer in clean boot and check if all the background program is causing this error message. To help resolve the error and other messages, you can start Windows Vista by using a minimal set of drivers and startup programs. This type of boot is known as a "clean boot". A clean boot helps eliminate software conflicts.

    The steps to perform a clean boot are given below:

    1 log on to the computer using an account with administrator rights

    2. click on start, type msconfig.exe in the start search box and press ENTER to start the System Configuration utility.

    If you are prompted for an administrator password or for confirmation, type your password, or click on continue

    3. on the general tab, click Selective startup, and then clear the check box load startup items. (The check box use the file Boot is not available.)

    4. on the Services tab, click to select the skin all the Microsoft services check box, and then click Disable all

    Note: Following this step lets services Microsoft continue to run. These services include networking, Plug-and-Play, record of events, error reporting, and other services. If you disable these services, you can permanently delete all restore points. Do not do this if you want to use with existing restore points system restore utility

    Once you start the office see if you get the error message. If not then follow the divide and conquer method mentioned in the article below to know which program is causing the problem.

    For more information about the clean boot, follow the below given link:

    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

    http://support.Microsoft.com/kb/929135

    When you are finished troubleshooting, follow these steps to reset the computer to start as usual:

    1. click on start, type msconfig.exe in the start search box and press ENTER.

    If you are prompted for an administrator password or for confirmation, type your password, or click on continue.

    2. on the general tab, click the Normal startup option, and then click OK.

    3. When you are prompted to restart the computer, click on restart

    Hope this information is useful.

    Amrita M

    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • For days now, my iPad Air insisted on the fact that it cannot connect to iTunes. Wifi works fine for applications and devices, and I tried all the options on the support page. Nothing has worked. What should I do?

    The time zone is correct, it is signed through "iCloud" in the settings and all the apps work relatively well, including those who are in need of the internet, so the problem is not the internet. However, the Air iPad is more connect to iTunes, it is impossible to update anything. It won't let me reconnect through 'iTunes and App Store' in settings, just tell me that it can't connect to iTunes everytime I try it. I also noticed that Game Center is strange, his page in settings will not be same load and he often delay signing in when I open an application compatible with it. My iOS is updated to 9.3.1. The only thing I can think is that I had to change my password recently, but he had me to login with the new password on the device, and this problem did not show up a few days later. I am at a loss on what to do at this point, and I already tried all suggested fixes Apple support. Are there patches less known who could solve this problem? Or, is this a widespread problem that apple is having this time with their servers?

    Hi TimeSeerStudios

    I don't see the failure:

    https://www.Apple.com/support/SystemStatus/

    Have you tried to close all applications and restart force (hold down the sleep/wake and Home buttons and do not let go until the screen darkens and the Apple logo appears)?

  • my iphone used to compress the video when I sent the files, and now my iPhone 4 and 5 trying to send uncompressed files that are too large to email.  The previous default system everything has worked, what has changed in the settings updated to IOS?

    Video compression for the email default disabled?

    I see that this has been released some time ago, but did you find the solution?  You start your email right now in the e-mail program, and then attach the 2nd video instead of the video, and then attaching it to an e-mail.  https://www.reddit.com/r/ios9/comments/3rzi4k/mail_no_longer_compresses_videos/

Maybe you are looking for

  • Satellite T210-113 - upgrade with WWAN card

    Hello! Receinty I bought the laptop ultraportable Toshiba T210-113. I love the device but lacks a level of mobility for me, because there is no preinstalled WWAN card With a broadband mobile PHONE (3G or 4G) card, it would be much more convenient to

  • define 4461 common mode dc offset

    Hi all Anyone know if it is possible to programmatically set a common mode DC offset to the differential output of a 4461 or what should I do with the external components? Please note that this is a different condition to define the differential DC l

  • my computer dell laptop started making a "carried away" sound when I start and closed. Very short - 1-2 seconds.

    When I start and stop the laptop it makes took sound, almost like an airplane fly across the screen. It has been published. How can I get rid of it please?

  • Problem synchronizing device WHEAT

    Hi all. I have not found an answer to my problem here or elsewhere, so I'm posting it now: I'm trying to pair a watch of sensor and heart rate Mio Alpha (a WHEAT device Smart Bluetooth 4.0 needed) my Z2 (4.4.4 Android). This was partly successful sin

  • Try to update the graphics card for Hp Slimline s3707c

    Hello I installed a 300w power supply and a 9800gt low profile with PIN 6 connected.  My computer does not read or use it. If it is connected directly the rest monitor orange and shows no display. Is is possible to upgrade this slimline for games?