How to merge two date ranges

Hello
I have the rest of the table. I want to merge the date ranges if dates are continuous and the value is the same. I use Oracle 10 g. Help, please.

START_DATE END_DATE VALUE
----------------------------------------------------------------

1/1/2008 12/31/2008 1234
1/1/2009 12/31/2009 1234


Exit statement SQL must be as follows:


START_DATE END_DATE VALUE
----------------------------------------------------------------

1/1/2008 12/31/2009 1234



Thanks in advance.

Published by: user3898545 on January 27, 2010 19:44

Hello

user3898545 wrote:
Hello
Dates will not overlap but sometimes start_date can be equal to end_date in a row.

Sorry, I'm not sure of that figure.
If the query I posted is not giving correct results, post some samples (CREATE TABLE and INSERT statements are best, but a clause WITH as Tubby displayed is correct) and the correct results, you need these data.

Please suggest if something needs to be done through pl/sql performance is also the key.

I don't see how the PL/SQL will help in this problem.

When two lines need to be combined, the end_date ranked sooner than always exactly 24 hours before the start_date on the line later?
If so:

WITH     got_grp         AS
(
     SELECT     data.*
     ,     end_date - SUM (end_date + 1 - start_date) OVER ( PARTITION BY  val
                                                                 ORDER BY       start_date
                                            ) AS grp
     FROM     data
)
SELECT       MIN (start_date)     AS start_date
,       MAX (end_date)     AS end_date
,       val
FROM       got_grp
GROUP BY  val
,            grp
ORDER BY  val
,            start_date
;

Published by: Frank Kulash, 28 January 2010 14:03
For example, a subquery added.

Tags: Database

Similar Questions

  • How to compare two dates and find exactly

    How to compare two dates and find the exact age of the person, no one could be an age of child 2 days or a month, or other.

    I'd really appreciate if someone help o

    Concerning

    After spending 2 hours, I go out with a solution by myself, how ever the function can be customize to check if the user enters date right.

    function findAge(subjectName,fromdate, todate) {
        console.log("findAge(fromdate, todate) is called now "+subjectName+"-->"+fromdate+"-->"+todate);
        if(todate) todate= new Date(todate);
        else todate= new Date();
    
        var age= [], fromdate= new Date(fromdate),
        y= [todate.getFullYear(), fromdate.getFullYear()],
        ydiff= y[0]-y[1],
        m= [todate.getMonth(), fromdate.getMonth()],
        mdiff= m[0]-m[1],
        d= [todate.getDate(), fromdate.getDate()],
        ddiff= d[0]-d[1];
    
        if(mdiff < 0 || (mdiff=== 0 && ddiff<0))--ydiff;
        if(mdiff<0) mdiff+= 11;
        if(ddiff<0){
            fromdate.setMonth(m[1]+1, 0);
            ddiff= fromdate.getDate()-d[1]+d[0];
            --mdiff;
        }
        if(ydiff> 0) age.push(ydiff+ ' year'+(ydiff> 1? 's ':' '));
        if(mdiff> 0) age.push(mdiff+ ' month'+(mdiff> 1? 's':''));
        if(ddiff> 0) age.push(ddiff+ ' day'+(ddiff> 1? 's':''));
        if(age.length>1) age.splice(age.length-1,0,' and ');
        console.log("===============================");
        console.log("Subject age is = "+age.join(''));
        console.log(" age Day = "+ddiff);
        console.log(" age Month = "+mdiff);
        console.log(" age Year = "+ydiff);
        console.log("===============================");
        var subjectAGE =  age.join('');
    
    }
    

    peardox Thanks for the reply

  • Filtering on two date range filters

    Hi people,

    I need your valuable contributions to the solution.

    It must filter the analysis by using two date range prompt as shown below.

    Of Date1 - Date1

    Of Date2 - Date2

    Note: We use only a Date column for the whole Date and so far

    Requirement:

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

    If Date1 and Date 1 is selected, then the first column of the analysis line should display as

    COLUMN1

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

    Of Date1 - Date1

    If both Date1 and Date 2 and Date1 AND Date2 is selected, then the first column of the analysis line should display as

    COLUMN1

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

    Of Date1 - Date1

    Of Date2 - Date2

    I hope I'm clear in the explanation of my requirement.

    Thanks to you all.

    DJ

    Check this box

    Oracle Business Intelligence, OBIEE 101: OBIEE between Dates invites

  • Does anyone know how to merge two workseets number for printing?

    How can I combine two spreadsheets in numbers for printing?

    Hi jj,

    I assume that you mean that you have a single document, which contains two worksheets, and that each sheet contains one table (only?).

    What do you mean by "merge two (booklets)?

    You mean you wan to place Tables of two leaves on a single sheet (this sheet would contain then both tables).

    Or do you mean you want to place all data on the two tables into a single table on one sheet?

    Or do you mean something different to both of these descriptions?

    Kind regards

    Barry

  • How to merge two partitions in XP

    I have Windows XP Service Pack 3.

    The space becomes very low on my NTFS Partition that contains Windows XP. There are partition with more than 100 GB of free space I want to access — preferably by merging two partitions or not not to resize the NTFS partition.
    From Googling, it seems that I cannot use the native Windows XP and need a third party application software, but I see that's not without risk of data loss.
    Can someone advise please?  Ty.

    6. as a result, select your C: drive and the option "Extend Volume". Your computer will automatically select the empty spaces available on your hard drive and you can change them if you want to do.

    This desire. Not. Work. for system volumes or boot or a partition on which the pagefile system is located.

    In addition, the GUI (using the disk management) method only works with volumes 'simple' or 'split', which are forms of "Dynamics" volumes and volumes of"base" that most of the people have set up.  http://support.Microsoft.com/kb/314343

    Given that the OP asked about the increase in the size of the partition system (my Partition NTFS which contains Windows XP) which is probably also the boot partition as where the pagefile, the posting is irrelevant.

    For Andrew pieces:

    Here are a few options in alphabetical order:

    Acronis Disk Director
    EASEUS Partition Manager free
    O & O Partition Manager 3

    Paragon Partition Manager

  • Newbie question: how to merge two pdf files?

    Hello, I have two PDF documents, and I'm putting one right in the middle of the other. Can someone guide me through this process? Thank you.

    Hello

    Please see the following link for information on how to merge PDF'.

    Acrobat help. Combine or merge files into a single PDF file

    Concerning

    Sukrit diallo

  • How to merge two values of resource bundle?

    Hi all

    JDev worm: 11.1.1.7

    I want to merge two values of resource bundle... How to do?

    like this #{expr? str1: str1 + str2}

    I tried like below and used some features of jstl... but no use did not work... got a parse exception, exception of compilation, etc...

    < af:outputText value = "#{row.accountName eq 'AccountName9'?" {resource ['LBL_WELC']: resources ["LBL_WELC"] + resource ['LBL_HOME']} "/ >"

    I would like to know how to do this?

    Kind regards

    Gopi

    The outputtext above is an example, I can use diff bundle keys like below,

    The principle is the same

    Dario

  • How to pass the date range as in URL filter go

    Hello

    I am trying to build a Url go that has two filters, date range & text. I built the url below, but he continues to throw an error. The url is not from the date max and the app starts following error:

    Error: Status: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 46048] Month DateTime value 0 0000-00-00 is off limits. (HY000)

    Go to Url: https:companyUrl? GB & Options = rfd & Path = / shared/CompanyID/link & P0 = 2 & P1 = eq & P2=CustomObject4.%22Indexed%20Pick%201%22 & P3 = Leasing & bet = P4 & P5 = ""-CustomObject4 Custom Attributes '. " ZDate_26 & P6 = 2 + Date % 20'2014-08-01'+ day % 20'2014-12-31'


    Please suggest.

    Thank you
    Kiran.

    It seems that you convert the data type of char to date in the URL, I don't think that this is possible.
    Your code is like
    & P6 = 2 + Date % 20'2014-08-01'+ day % 20'2014-12-31'

    It suppose to be & P6 = 2 + 2014-08-01 + 2014-12-31

    I suggest doing the formatting for this filed using column properties and try.

    Hope this help, pls mark if yes ;)

  • How to merge two slideshows macOSX

    I'm trying to merge two slideshow on my mac Pro or Imac. If possible, I would like to keep the original music in both. But it is not critical.

    Thank you

    Slide show projects cannot be merged.

    If you visit both attractions like a video, you can add the two points of view in iMovie and display a merged video.

    Otherwise, duplicate a slide show and add photos of the second presentation to the other.

    What version of iPhoto do you use?

  • How to merge two images in 14 elements?

    I've read a few articles on different ways to merge two photos in 14 elements using Photomerge, but I don't see a Photomerge announced on my new screen 14 items.  I said to go to "improve, Photomerge, Photomerge dial", but only 'Enhance' watch.  Then I read to go to "Editor, guided edits" or in the Organizer, go to "Edit, Photomerge."  I can't find anything that says Photomerge.  Help, please! -Thank you very much, Anna

    annam61239719 wrote:

    I've read a few articles on different ways to merge two photos in 14 elements using Photomerge, but I don't see a Photomerge announced on my new screen 14 items.  I said to go to "improve, Photomerge, Photomerge dial", but only 'Enhance' watch.  Then I read to go to "Editor, guided edits" or in the Organizer, go to "Edit, Photomerge."  I can't find anything that says Photomerge.  Help, please! -Thank you very much, Anna

    The Photomerge function was moved to 'Expert' display mode to the mode "guided edit.

    What has not changed is that you can always select your files in the organizer and use the Edit menu > Photomerge.

  • SQL to generate the intervals from date of 6 months each, between two date ranges

    Hi all

    I looked in the forums, if someone uses CREATE_CHUNKS_BY_SQL for dates, but no luck.
    I want to update a table using pieces of dates.
    I need to generate date ranges to divide them by pieces.

    I have a table where I know that max (sales_date) and min (sales_date).
    Lets say max (sales_date): min (sales_date) 01/01/2008: 31/10/2010

    I want to break in intervals of 6 months (180 days) as below:
    chunk_id     start_date     end_date
    --------     ----------     --------
      1          01/01/2008     06/30/2008
      2          01/07/2008     12/31/2008
      3          01/01/2009     06/30/2009
      4          01/07/2009     12/31/2009
      5          01/01/2010     06/30/2010
      6          01/07/2010     10/31/2010
    He didn't exactly finish end of the month. Basically, I need these beaches of dates at apart 180 days.

    I appreciate if someone can throw some ideas on this.

    Thank you
    Raj.

    Hi, Raj,

    Sorry, it is unclear what you are asking.

    To generate a list of dates starting with min_sales_date and including all the 180 days after that up to (but not beyond) max_sales_date:

    WITH     got_params     AS
    (
         SELECT     DATE '2008-01-01'     AS min_sales_date
         ,     DATE '2010-10-31'     AS max_sales_date
         FROM     dual
    )
    SELECT     min_sales_date + (180 * (LEVEL - 1))     AS grp_start_date
    FROM     got_params
    CONNECT BY     LEVEL <= CEIL ( ( (max_sales_date - min_sales_date)
                                    + 1
                           )
                         / 180
                         )
    ;
    

    Output:

    GRP_START_D
    -----------
    01-Jan-2008
    29-Jun-2008
    26-Dec-2008
    24-Jun-2009
    21-Dec-2009
    19-Jun-2010
    

    December 16, 2010 is 180 days after June 19, 2010, but it is not displayed, because is after max_sales_date, which is 31 October 2010.

    I hope this helps you.
    Whenever you have any questions, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.

  • How to compare two dates and times in BPEL?

    Hi all
    I need to compare two dates and times in a switch activity, but could not find any function for her.

    My switch like this activity:

    case Date1 > date2:
    do something;
    otherwise:
    do something;

    He is not such a function in 'The functions of Date' and can not find this function to xpath.

    IBE, there is no function for a period of time to make (less one date of another?...) If this return to the data compare question).

    Thank you.

    Hello

    Logic function as more/less function can be used to compare two dates so that same comapring two numbers.

    Ex: If your variable reception contains two pieces of data such as date1 and date2, then you can use format in condition switch below.

    XpathXpression (date1) > XpathXpression (date2)

    hope this will help you.

  • How to assimilate two Dates in flex

    Hello
    I need to compare two dates, the < and > works pretty but == show no results, even if two dates are equal. Now I'm equating taking date, month, year, hour, time of two dates. Y at - there no direct way two find if two dates are equal or not.

    Date are usually stored more than a millisecond to a point of reference, in flex, this reference is midnight Jan 1, 1970. There are two ways to get this number: property at the time when the valueOf() method. Then

    var d1:Date =...
    var d2:Date =...

    If (d1.time == d2.time) or if (d1.valueOf () == d2.valueOf ())...

    ATTA

  • How to merge two discs into one?

    I recently updated my OS to Windows XP Edition Home Premium to Windows XP Pro. One way or another I have now two drives (Local 'C' and 'E' Local drive).  When I start the computer it opens to E drive and I continually have a message that I don't have enough disk space on drive E.  How can I megre present two discs into one?  I tried to copy the contents of the C drive in drive E, but I get the message that I don't have enough space on this drive.

    Recommendations or suggestions will be appreciated.  Thank you.

    Ernie...

    Hi Ernie,.

    I suggest you to follow these steps and check if the problem persists.

    a. go to the start menu and open 'control panel '.
    b. Select the option "System and Maintenance" If you use the Control Panel view home and 'Administrative tools' If you use the "classic" view
    d. in the "Administrative Tools" section, select "format and create partitions on the disk.
    e. for users "Classic view", select "Computer management" and select "Storage". Once finished, click on "disk management".
    f. when the list of your reader, choose the one with which you want to merge your disk partitioned with (for example drive E :) and select 'Delete Volume'.)
    g. therefore, select your C: drive and the option "Extend Volume". Your computer will automatically select the empty spaces available on your hard drive and you can change them if you want to do.

    Note: Make sure that you back up the data and then remove drive E.

  • How to merge two address books

    I would like two of my existing address books TB merge into one, eliminating the duplicates contacts.

    Drag and drop in an address book to another. You can of course select multiple Contacts using the usual shift and control, click methods.

    I use the addon double-contact-manager to sort the replicated contacts.

    https://addons.Mozilla.org/en-us/Thunderbird/addon/duplicate-contact-manager/

    How to install: http://xenos-email-notes.simplesite.com/416814616

Maybe you are looking for

  • Air IPad also get stuck cant activated after update 9.3 not only the ipad 2

    My ipad air also get stuck cant activated after update 9.3 Thursday so far seems that apple did not the solution... I did also his already suggests. Remove all the account update DHU icloud and restore from itunes, even now downgrade to 9.2.1 but sti

  • Cisco IPS 4255 rescue

    I am interested in the datasheet of IPS-4255 and found that a third-party product for automated backup is necessary I do not understand how third party is necessary is what it means that IPS4255 is not relief when the sensor fails? I couldn't find th

  • How to compress file .mov? . RAR, zip, and. TAR to stay the same size?

    I want 2 .mpv files by e-mail, but compressors do not change their size. How can I do?

  • When using the merge and when to use updated

    Hi friends,Given the best performance... purpose of this discussion is when we should use statement UPDATE and when we should use MERGE statement in oracle update of thousands of records.Kindly Guide.Kind regardsHimanshu

  • clarification of oem12c installation instructions

    Thank you for taking my questions!Background:I try to install oem12c 12.1.0.3 (simple installation) on a windows 2008 (11.2.0.4 database).(Only currently have 3 production databases and development 9 so I intend using the SIMPLE installation method.)