Eliminate duplicates while counting dates

Hi all

Version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0.


How to count the dates and eliminate duplicate dates.

For example,.

Name from Date to Date

AAA 31/05/2014-06/13/2014

AAA 14/06/2014 06/27/2014

AAA 21/06/2014 07/20/2014

AAA 21/07/2014 08/20/2014

We want the output as,

County of name not days

AAA 14

AAA 14

23 AAA (in this case must be eliminated 7 days from June 21, 2014-20/07/2014' because it is already counted dates previous ie.'06/14/2014 - 27/06/2014 '.) If we want the exit 23)

AAA 31

Thank you

Pradeep D.

Untested carefully... But can give you an idea:

-----

WITH t
     AS (SELECT 'AAA' nm,
                TO_DATE ('05/31/2014', 'MM/DD/YYYY') from_dt,
                TO_DATE ('06/13/2014', 'MM/DD/YYYY') TO_DT
           FROM DUAL
         UNION ALL
         SELECT 'AAA',
                TO_DATE ('06/14/2014', 'MM/DD/YYYY'),
                TO_DATE ('06/27/2014', 'MM/DD/YYYY')
           FROM DUAL
         UNION ALL
         SELECT 'AAA',
                TO_DATE ('06/21/2014', 'MM/DD/YYYY'),
                TO_DATE ('07/20/2014', 'MM/DD/YYYY')
           FROM DUAL
         UNION ALL
         SELECT 'AAA',
                TO_DATE ('07/21/2014', 'MM/DD/YYYY'),
                TO_DATE ('08/20/2014', 'MM/DD/YYYY')
           FROM DUAL),
     tt
     AS (SELECT nm,
                from_dt,
                to_dt,
                (to_dt - from_dt) total_diff,
                CASE
                   WHEN   LEAD (from_dt, 1)
                             OVER (PARTITION BY nm ORDER BY from_dt)
                        - to_dt < 0
                   THEN
                        LEAD (from_dt, 1)
                           OVER (PARTITION BY nm ORDER BY from_dt)
                      - to_dt
                      - 1
                   ELSE
                      0
                END
                   diff
           FROM t)
SELECT nm,
       from_dt,
       to_dt,
         1
       + total_diff
       + LAG (diff, 1, 0) OVER (PARTITION BY nm ORDER BY from_dt) final_diff
  FROM tt

Output:

------------

NM FROM_DT TO_DT FINAL_DIFF

AAA 2014 6/13/5/31/2014 14

AAA 2014 6/27/6/14/2014 14

AAA 23 6/2014 7/20/21/2014

AAA 31 7/2014-8/20/21/2014

See you soon,.

Manik.

Tags: Database

Similar Questions

  • eliminate duplicate lines

    Hello

    I have a report that shows some of the duplicate records and need to eliminate duplicate rows on the report. How to hide the lines duplicated on the presentation of the report so that only 1 row appears on the report instead of having the same line appearing more than once? I use BI Publisher 11.1.1.7. Thank you.

    It is advisable to eliminate duplicate rows to the data model, however, if you do not want to do it on the model please see below

    Whereas you use RTF model

    Change your for each tag to something like this

    If you don't succeed; Thanks for posting your model and an example of xml data

  • While the data activity indicator display is recharging of Webservice

    Hi guys,.

    How can I display an indicator of activity while the data or recharging of Webservice?

    Currently I used Timer to set the agenda.

    Thanks in advance.

    Concerning

    Hey,.

    You can make it visible when you start the application, and on the function of earphone Event.COMPLETE, you can configure it to hide the indicator. hope that helps. Good luck!

  • Issue while loading data using the file Rules Essbase

    Hi all

    I am facing problem while loading data using the Rules file. In the rules file, I rejected several members in two areas (two dimensions). Now if I load the data using the rules file I'm getting errors for all members in the dataload.err file. If I reject mutiple members of a single field, the data load without settling errors in the dataload.err file.

    I want to know how rmany members of several fields of ejection for loading data using the file Rules Essbase? Is it possible?

    Okay, okay... I think that you must assign Global Select / reject Boolean in the parameters of loading data as 'Or':

  • What makes a "curl" in the lower left corner of an average of photo double and is anyway to eliminate duplicates of theses?

    What makes a "curl" in the lower left corner of an average of photo double and is anyway to eliminate duplicates of theses? I have thousands and do not know whence they came or how to get rid of them in my catalog.

    Don

    Hi drdonrock,

    The "curl" in the left corner of the image is that the image is a virtual copy of the original Image.

    You can delete the virtual Copies by clicking on pictures in the catalog Panel and then selecting filter attribute.

    From there please option virtual Copies, and from there, you can remove all virtual copies.

    Please let us know if it helps.

    Kind regards

    Tanuj Sandal

  • Update the duplicate while maintaining the original data

    Hi all

    By a mistake, I have created a table, and now we have duplicate entries, while the original is also among them.

    In my view, the min (id) will be the original data. How can I delete the duplicate record while maintaining the original and the rest of the table data.

    This is the structure of the sample where the XREFand UML combination will make the records in the table as unique.

    Because the ID is sequence uses, it will be always unique.

    ID XREF UML name
    101121KatinRiha
    102139PintKebit
    103139PintJosh
    104121KatinWebber
    10589187SorbetBimbles
    10979817PLEsMark
    658139PintStefanny

    I got it thank you.

  • continuous performance counter data

    Hi all

    I need assistance in the collection of data from a counter entry. I have a flow sensor that creates an output up to 600 Hz. frequency I plugged on the entry of a counter on my DAQ hardware, and in Labview, I plugged the DAQ assistant to a curve of waveform in a while loop. When I run it, it runs until it is among the samples and then gives the error 200284 and then shows the frequency over time on the chart.

    However, I would like to see the frequency over time in real time on the chart, while it is running, and I would also like to run continuously until I hit the stop button. Can someone explain how this is done?

    Best regards

    Allard

    Allard,

    you stop the acquisition in the loop. This is why buy you a single package (of 1000 samples) and finish the acquisition. After that, the loop runs immediately create 100% CPU load on a carrot and basically doing nothing except waiting for the stop button to be pressed.

    Learn more about the shift registers to store job and put the task to stop outside the loop. In the loop, modify the terminal to stop the loop itself to stop if the stop button has been pressed OR if an error in the acquisition took place.

    Your current implementation will wait 1000 samples and display in the chart. The next update will completely replace the old conspiracy. According to the speed, you will get this behavior (@600 Hz about once every 2 seconds). You can do the following:

    • Reduce the number of samples for example 100

    • Use a graphic instead of waveform graphic waveform (for 'history')

    or

    • Set up a ring buffer using a shift register to update a chart similar to a graphic waveform

    Norbert

  • get comments while collecting data

    I have a program which collects data in the lab and displays on the screen as he goes.  I want to add a comment feature, so that if the user sees something interesting she could click on "Comment" and add a comment that will be saved in a text file at the end of the session of data acquisition.  I would like to 'time stamp', comment by using the time (since the beginning of the acquisition) when you press button "comment."  So, I wrote a piece of code (enclosed) test, that does not work as you wish.  When the code begins, he's waiting for the user to start a timer (data acquisition would begin at this point, the full blown program).  Then start the timer, and the program waits for the user to click on 'Stop' and then displays the time elapsed between start and stop.  At least it is supposed to work this way.  While he waits for the shutdown, it monitors the "Comment" button and gets user input if the comment is.  He adds the time current for the comment by the user, as you wish.  It's just, the program pays attention to the comment button and does not pay attention to the Stop button. This program does not stop when the user presses Stop.  I want to enable zero, one or more user comments in the period between 'Start' and 'Stop '. What should do?  Thank you.

    Try running this execution highlighting (icon in the toolbar "bulb") and you will see what happens.  Your code is, in fact, attentive to the stop button - just not when you want.  If you click on 'Stop' and then click on the "Comment" button, you will find that your code stops as expected.  The problem is that your inner while loop (check the 'Comment' button) runs continuously, and the code checks the condition of the outside loop while (the one that is connected to the "Stop" button) until the inside while the loop ends.

    A better solution would be to eliminate all the structures of the sequence and all nested in loops and replace it with a single while loop.  Inner loop while could check to the Stop button to terminate the loop and the code to manage the comment function within a structure of business wired to your comment button.

  • Request to eliminate duplicates

    I have a table that lists some data. Every day should have a single record per organization. I'm weeding out duplicates in a query. Any of the duplicates will be removed, so I could use a (where rownum = 2 clause), but I don't know how to get there.

    This query exposes the duplicates:
    select DATE_INDEX, ORG_ID
      from STAFFING_TURNOVER
     group by DATE_INDEX, ORG_ID
     having COUNT(ID) > 1
     order by DATE_INDEX, ORG_ID
    Can someone help me to turn this into a delete query that removes the second record? Because it is based on a combination of date + organization, the syntax for a deletion based on the subquery is escape.

    How about this one?

    remove from STAFFING_TURNOVER
    where rowid NOT IN (select MIN (rowid) of STAFFING_TURNOVER
    DATE_INDEX group, ORG_ID)

  • How to eliminate duplicates in this table

    SELECT sti.item,
    MI: ITEM_DESC,
    Count (STI. Item) item_count,.
    d.dept_name,
    d.group_no,
    d.BUD_INT,
    STI.standard_unit_retail,
    ISC.unit_cost,
    margin (sti.standard_unit_retail - isc.unit_cost).
    Count (STI. Item) *(STI.standard_unit_retail-ISC.unit_cost) total_amount,.
    County (sti.item) * isc.unit_cost Tot_Sales,.
    STH. TRAN_DATETIME
    Of
    sa_tran_item sti,
    item_supp_country Sai,
    IM item_master,
    STARTING d,
    sth sa_tran_head
    WHERE
    STI. Item = isc.item
    and sti.item = im.item
    and d.DEPT = sti. DEPT
    and sth. TRAN_SEQ_NO = sti. TRAN_SEQ_NO
    and sth. TRAN_DATETIME between: p1 and: p2
    Group of sti.item, im. ITEM_DESC, d.dept_name, d.group_no, d.BUD_INT, sti.standard_unit_retail, isc.unit_cost)
    STI.standard_unit_retail - isc.unit_cost), STH. TRAN_DATETIME

    When I combine this STH. TRAN_DATETIME I have some duplicate values in STH. TRAN_DATETIME repeated dates... How to avoid duplicates and at the same time the group the STH. TRAN_DATETIME...
    Please help... urgent

    Hello

    If you mean that you must get rid of time, then you can put TRUNC around STH. TRAN_DATETIME:

     SELECT sti.item,
    im.ITEM_DESC,
    COUNT(sti.item) item_count,
    d.dept_name,
    d.group_no,
    d.BUD_INT,
    sti.standard_unit_retail,
    isc.unit_cost,
    ( sti.standard_unit_retail-isc.unit_cost ) margin,
    count(sti.item)*(sti.standard_unit_retail-isc.unit_cost) total_amount,
    count(sti.item)*isc.unit_cost Tot_Sales,
    trunc(sth.tran_datetime) TRAN_DATETIME
    FROM
    sa_tran_item sti,
    item_supp_country isc,
    item_master im,
    deps d,
    sa_tran_head sth
    WHERE
    sti.item = isc.item
    and sti.item=im.item
    and d.DEPT=sti.DEPT
    and sth.TRAN_SEQ_NO = sti.TRAN_SEQ_NO
    and sth.TRAN_DATETIME between :p1 and :p2
    group by sti.item, im.ITEM_DESC, d.dept_name, d.group_no, d.BUD_INT, sti.standard_unit_retail, isc.unit_cost, (
    sti.standard_unit_retail-isc.unit_cost ), trunc(STH.TRAN_DATETIME)
    

    Herald tiomela
    http://htendam.WordPress.com

  • Y at - it an easy way to eliminate duplicate them slides

    I have thousands sldes and many are duplicates because of their change on photoshop.com. Will appreciate knowing how elimate groups of slides without removing those which are currently used in slide shows.

    Glad you're enjoying the book, George!

    Unfortunately, I'm not sure of an easy way to eliminate the duplicate in the Organizer files.

    You could try (in the Organizer) file/reconnection/missing files. The program will search for all of your files and indicate problems. It could also indicate the duplicates. I'm not sure. But it's a good way to keep your catalogue up-to-date anyway!

    BTW, you can avoid the display of your phone. As you can see, when you make your message includes your name, address, telephone number and e-mail address. This leaves you very vulnerable to spammers.

  • Helps the acquisition of photon counter data using LabView 12

    Hey all,.

    Student graduate Chemistry here new to LabView and are looking for some help moving in the right direction.  I'm looking for help with connecting my meter to 12 LabView for data acquisition of trace-fluorescence photon PerkinElmer SPCM-AQR-14 (now owned by Excelitas Technologies).  I just want to be able to acquire number of photon counts vs. time.  Currently, I installed a PCI-6601 and use a BNC-2121 to connect the BNC of the sensor output.  The detector has a pulse output digital TTL with 30 ns pulse width, and by contacting technical support on this issue, I was told that this pulse width was too short to always detected by the 6601, but can still go ahead and give it a try.  Basically, if everyone is familiar with how to start with this configuration, ANY help would be greatly appreciated.  As I said I'm all new to LabView and am currently spend all my spare time reading manuals and help files.

    Please let me know if you need any kind of information to make me understand what I'm doing.

    I would say something like this:

    A measurement period the registry account out of the entrance of the samples as well as gives the meter.  You will basically measure the 'period' of your sample clock fixed regarding ticks of the external photon signal.

    According to the downtime, you may need to re-read several samples per loop so that the software can keep up with the incoming data.  Also, the first sample is not useful because it represents the County between the software from the task of entry of the meter and the first clock signal - you should disregard/erase the first sample (or if you want you can set up a trigger to begin arms).

    To do the same thing by using an edge County task would require using both the sample clock AND a counter reset signal - this not is not supported on 6601/6602 (even if it would be possible to set it up that way on a device of STC - 3 as a series of X).

    Best regards

  • I have a problem with writing able to Excel after 15 s do-while of data acquisition

    Dear Sir/Madam

    Currently, I am trying to write a 15 seconds of action in an excel file. The measure of 15 seconds is made by do-while function.

    But unfortunately, after 15 seconds, not all data can be written to the excel, single reading has been written successfully.

    Writing custom to the file is outside of the do-while loop.

    Could you please tell me how to solve this problem?

    Thanks a lot for your help.

    Kind regards

    Ken


  • How to eliminate duplicates in the playlists.

    Sometimes I drag an album to a playlist... create duplicate songs.  How can I easily identify.  Or maybe avoid - like iTunes will ask if you want copy duplicates

    Hi vbjnk,

    (a) are you referring to Windows Media Player? I would like to know if it is something else

    (b) this only happens with a particular album?

    I suggest you try the following steps:

     

    Step 1: Check the location of the file and delete the duplicate entry

     

    1. read the album; Right click on the item\file double and select Properties

    2. check the location of the file and you can remove the copy element

    The player is followed by a file and replace your library entries that point to files in this folder. For example, you might have copied the files into a new folder but does not delete the original files in the folder in question.

    To prevent the entries again added to your library

    1.

    Delete or move the files in the folder in question

    The monitor records is useful for automatically updating your library when the controlled media digital media files information. However, you must be careful to keep the list of files controlled by the player to date to avoid invalid entries in your library.

    For more information on the tracking folder, please see the link below

    Add items to the Windows Media Player library

    http://Windows.Microsoft.com/en-us/Windows-Vista/add-items-to-the-Windows-Media-Player-library

    If the problem occurs because several albums try step 2

    Step 2: You can rebuild the Player Windows Media database library. To do this, follow the steps mentioned in the link below

    You cannot view, add, or delete items in the library of Windows Media Player 11

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

    Step 3: Stop the entries in double or invalid to be added to my library when I play the music files

    When you move digital media files on your computer, the file name and file path information remain unchanged in your library. Then when you select a file to play to its new location, a new entry is created in your library if you select the option automatically added to your library when played. As a result, your library can quickly contain a large number of entries, duplicate or invalid.

    To prevent it be automatically added to your library of music files

    1.

    In Windows Media Player, on theTools menu, clickOptions.

    2.

    On the Player tab, clear the checkbox Add music files to library when played .

       
       

    Note: Now, when you play music on your computer or the Internet, the file will not be added automatically to your library.

    Thank you, and in what concerns:

    Ajay K

    Microsoft Answers Support Engineer

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

  • Time increasing while sending data via http repeatedly on the storm

    Hi all!

    My application sends data (in general, this is a picture of ~ 1200 Kb) to the server via http.

    The data are sent ok, but the when I send data several times (without leaving the application) the time devoted to writing the data in the outputStream develops. On first use, it takes usually ~ 50 seconds, the second seconds of ~ 70, the third seconds from ~ 100... I see this problem only on the storm, others (Curve 8900, Bold, Tour) are OK. The url is used on Storm is: http://xxxxxxxxxxxxx.com/mobile/mobile.asmx;deviceside=true

    Here is the code snippet:

    private static WSResponse send(byte[] xmlBytes, WSResponseParser parser) throws Exception {
    
            HttpConnection connection = null;
        OutputStream outputStream = null;
    
           try {
                connection = (HttpConnection)Connector.open(WifiChecker.getURL(URL), Connector.READ_WRITE, true);
    
                connection.setRequestMethod(HttpConnection.POST);
                connection.setRequestProperty("Content-Type", CONTENT_TYPE);
                connection.setRequestProperty("Content-Length", String.valueOf(xmlBytes.length));
    
                outputStream = connection.openOutputStream();
    
                int offset = 0;
                int chunk = DATA_CHUNK_SIZE; // 1024
                int len = xmlBytes.length;
                while (offset < len) {
                    if (offset + chunk >= len) { // avoiding OutOfBounds Exception
                        chunk = len - offset;
                    }
                    outputStream.write(xmlBytes, offset, chunk);
                    offset += chunk;
                }
    
                xmlBytes = null;
    
                String response = getResponseAsSting(connection);
    
                WSResponse wsResponse = null;
                try {
                    wsResponse = parser.getWSResponse(response);
                } catch (Exception e) {
                    throw ApplicationException.invalidWsResponse();
             }
    
                if (!wsResponse.isSuccess()) {
                    throw new WSFailureException(wsResponse);
                }
    
                return wsResponse;
    
            } finally {
                IOUtils.safelyCloseStream(outputStream);
                IOUtils.safelyCloseStream(connection);
                if (xmlBytes != null) {
                    xmlBytes = null; // notify VM it can safely free the RAM
                }
            }
    

    I thought it may be a memory problem, so I manually cancel xmlBytes, but which does not solve the problem.

    Any ideas?

    Thanks in advance,

    Arhimed

    P. S.

    There is no question about Simulator, only on a real device of the storm.

    MSohm, thanks for your response.

    Fortunately, I have just fixed the problem. The problem was not in the code above, but in the code that made the xmlBytes. I converted bytes of the image base64 and looks like I did it dangerously on the use of the memory.

    Thanks again for your attention to this thread!

Maybe you are looking for

  • Camera work is not on Windows 10

    Hi, after installing Windows 10 on some PCs, I have no access to the camera on them in Skype. If I open the camera app, it works and not exceeding not black comes from the camera when using Skype

  • HP pavilion touchsmart: Discussion on laptops and laptop

    ask your entry, please: product G9D77UA #ABA model 15-r052nr rev 2211-100 CCDI 0976100000405F00000620180 I want to identify the good motherboard, do not know what is the motherboard number - thank you, Jack

  • ODD has stopped working on the Satellite Pro A200

    I have a Satellite Pro A200 - PSAE1E. The CD/DVD was working fine and then stopped. I put in another CD and it went through the process of trying to find - but could not.It ejects the disc. I tried with other CD in the same direction. Yellow light wo

  • Satellite M40-282: I don't have access rights to run Power Saver

    I installed GST when I reinstalled my new OS manuallyand I installed GST but he did not show up to reinstall after.In the control panel when I try to click the GST that it says 'cannot be opened because you do not have access rights to run Toshiba Po

  • Version of Windows 64-bit Server and the remote your 2161DS-2 console switch

    I have a Dell 2 your 2161DS remote console switch connected to the servers of 7 or 8.  Recently, I removed several servers and install 3 new devices; a Windows Server 2003 (32-bit) system; a system of Windows Unified Data Storage Server 2003 (64-bit)