Flattening of the ranges that overlap

I have data that looks like this:
(SKU, from_day, to_day)
(1, 1, 3)
(1, 2, 8)
(1, 7, 9)
(2, 2, 4)
(2, 6, 8)
I need to reduce it to the range for each category:
(1, 1, 9)
(2, 2, 4)
(2, 6, 8)
There may be many more records for each category, but this should be sufficient to illustrate the problem.

I have three SKU 1 positions that were in place for a range of dates. The first element was there from day 1 to 3; the second days 2 to 8; the third days 7 to 9. These days this overlap, I would like to report on the maximum range of days that overlap - that is to say, that I had an element of SKU 1 present of the day 1 to day 9.

I have two SKU 2 elements that were present in the location for the date interval. The first element was there for days 2 to 4; the second from 6 to 8 days. Given that these days do not overlap, I need to report separately.

Can someone help me to write SQL that will accomplish this? It seems that I could use the syntax to CONNECT BY PRIOR, but I don't see how.

Hello

Here's one way:

WITH     got_grp_start     AS
(
     SELECT     sku, from_day, to_day
     ,     CASE
              WHEN from_day <= MAX (to_day) OVER ( PARTITION BY  sku
                                                   ORDER BY      from_day
                                    RANGE BETWEEN UNBOUNDED PRECEDING
                                          AND     1      PRECEDING
                                     )
              THEN 0
              ELSE 1
          END          AS grp_start
     FROM     table_x
)
,     got_grp          AS
(
     SELECT     sku, from_day, to_day
     ,     SUM (grp_start) OVER ( PARTITION BY  sku
                               ORDER BY          from_day
                         ) AS grp
     FROM    got_grp_start
)
SELECT       sku
,       MIN (from_day)     AS grp_from_day
,       MAX (to_day)          AS grp_to_day
FROM       got_grp
GROUP BY  sku
,            grp
ORDER BY  sku
,            grp_from_day
;

This is an example of a problem of the English Channel , where consecutive lines (here, means consecutive in order of from_day) into groups, but there is nothing in any individual line which indicates which group belongs to this line; We must compare each row of other rows in the same score to determine if a new group (a ' handle') started this line or not. It's a little trickier than most other neck problems, because we had (I assume) data like this:

INSERT INTO table_x (sku, from_day, to_day) VALUES (9, 1, 5);
INSERT INTO table_x (sku, from_day, to_day) VALUES (9, 2, 3);
INSERT INTO table_x (sku, from_day, to_day) VALUES (9, 4, 6);

When deciding if a round begins with the 3rd rank, we cannot just look at the previous 1 row; To watch all the previous lines.

After that we have determined where each round begins, we use the analytical SUM function to see how many innings have already started, i.e. to which group each line belongs. Once we have the number of group, getting high and low group limits is just a matter of using MIN and MAX.

Published by: Frank Kulash, October 3, 2012 18:08
Additional explanation

Tags: Database

Similar Questions

  • How do you find the range that a function belongs?

    If you discover a function and want to use it, how do you find the range that a function belongs?  I know how to find a function, but don't tell me how to find his range.

    Thanks in advance.

    When you search for a function and double-click on the result, it will bring to the top of the tree of range of features and show you how to get to this function:

  • 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...

  • Separate the objects that overlap in a 1 bit image

    I do a program that takes pictures of coins and transforms them into a 1-bit image, is it possible to treat the parts that may overlap to see them as separate rooms

    Vision developmrnt monule contains methods for this - a solution involving either a watershead processing to separate the opjects.

  • Replace from the Clipboard, or "connect the wires that overlap?

    I'll go by many of my first diagrams and clean code

    with things I've learned since I started using Labview.  A lot of this involves deleting

    objects, then copy/paste of a conception of good reference in the old design.   However,.

    This often leaves a large number of broken wires to clean.    For example, where I had individual

    enumerations that are used in the design, I am replacing them with typedef enumerations.

    (I couldn't typedef controls to appear in my palette of functions, but it is a question

    for another post)

    As it seems to be my only choice ' replace-> select a VI-> [file .llb]->-> [OK] typedef.

    or remove the old one, paste a new, ctrl-B and rewire.  This second option seems

    to go faster than the first.  But in both cases, there is a lot of click and drag to replace a

    control, and there are dozens of them to do.

    Therefore the routing of the wires is the same, but it takes time to connect them all back.

    Is it possible to tell LV "re - connect the broken wires that overlap the pins."

    overall or in a given area?

    Or y at - it a way to simply "replace from the Clipboard?

    Thank you and best regards,

    -- J.

    If you do a find > anyway, the dialog box that opens has a button replace.  After selecting the replacement, one of the options is to replace all.  This should save time if you have multiple copies of the original constants or controls made from the control.

    Lynn

  • How can I adjust the shapes that overlap the page?

    I'm working on a holiday brochure 270 page. I usually work with Photoshop, but I know that's not ideal for brochures, then worked along side another designer with InDesign. I picked up almost everything to get me going which is great. However, I am stuck on best practices for the bottom.

    The idea is that each page with a hotel will have the same style of background, which consists of a few circle shapes that are slightly different shades. Circles leave the edges of the page, to just form a curve across the page. Each different destination will have these forms in different colors, so that the customer wants to be able to change the colors autour once I put the brochure their.

    I work with what I have now, but it is a little ugly looking having huge circles leave the edges of the page in "Normal" mode.

    Is it possible to cut the rest of the form that is not inside the purge?

    draw a rectangle the size of the page + bleed area. Cut your background of the circle, and then paste in the rectangle. Ideally, it should be on a master page (a master page by destination).

  • To ignore the date ranges that overlap

    Hi guys,.

    I have the tables below

    Periods

    START_DATEEND_DATEID
    30-SEP-0513 OCTOBER 051
    12 OCTOBER 0514 NOVEMBER 052
    15 NOVEMBER 0515 DECEMBER 053

    T1

    DAT_COLIDAMOUNT
    11 OCTOBER 05110
    12 OCTOBER 05110
    16 NOVEMBER 05110

    I need to ignore the remaining date range if it overlaps when comparing dat_col from T1 between the dates of beginning and end of periods table. Always need to consider the first periods

    output something like this

    IDID_1START_DATEEND_DATEDAT_COL
    1130-SEP-0513 OCTOBER 0511 OCTOBER 05
    1130-SEP-0513 OCTOBER 0512 OCTOBER 05
    1315 NOVEMBER 0515 DECEMBER 0516 NOVEMBER 05

    I use query

    Select a.id, b.id, b.start_date, b.end_Date, a.DAT_COL from T1 a, (select id, start_date, end_date periods) b

    where a.dat_col between b.start_Date and b.end_Date

    Group of a.id, b.id, b.start_date, b.end_Date, a.dat_col

    order of b.start_date;

    IDID_1START_DATEEND_DATEDAT_COL
    1130-SEP-0513 OCTOBER 0511 OCTOBER 05
    1130-SEP-0513 OCTOBER 0512 OCTOBER 05
    1212 OCTOBER 0514 NOVEMBER 0512 OCTOBER 05
    1315 NOVEMBER 0515 DECEMBER 0516 NOVEMBER 05

    Test case:

    CREATE TABLE 'PERIODS '.

    ("START_DATE" DATE,

    "END_DATE" DATE,

    'ID '.

    ) ;

    Insert into periods (start_date, end_date, ID) values (to_date('30-SEP-05','DD-MON-RR'),to_date('13-OCT-05','DD-MON-RR'),1);

    Insert into periods (start_date, end_date, ID) values (to_date('12-OCT-05','DD-MON-RR'),to_date('14-NOV-05','DD-MON-RR'),2);

    Insert into periods (start_date, end_date, ID) values (to_date('15-NOV-05','DD-MON-RR'),to_date('15-DEC-05','DD-MON-RR'),3);

    Insert into T1 (DAT_COL, ID) values (to_date('11-OCT-05','DD-MON-RR'), 1);

    Insert into T1 (DAT_COL, ID) values (to_date('12-OCT-05','DD-MON-RR'), 1);

    Insert into T1 (DAT_COL, ID) values (to_date('16-NOV-05','DD-MON-RR'), 1);

    CREATE TABLE 'T1 '.

    (DATE OF THE 'DAT_COL',

    'ID '.

    );

    Hello

    If you really want to use something close to what you posted, then you can do it like this:

    WITH got_r_num AS

    (

    SELECT a.id

    b.id AS id_1

    b.start_date

    b.end_date

    a.dat_col

    , ROW_NUMBER () OVER (PARTITION BY a.id, a.dat_col)

    ORDER BY b.start_date, b.end_date

    ) AS r_num

    FROM one t1

    ,         (

    SELECT id, start_date, end_date

    Periods

    ) b

    WHERE a.dat_col BETWEEN b.start_date

    AND b.end_date

    GROUP BY a.id, b.end_date, a.dat_col, b.start_date and b.id

    )

    SELECT id, id_1, start_date, end_date, dat_col

    OF got_r_num

    WHERE r_num = 1

    ORDER BY start_date

    ;

    Note that the WITH clause, that's essentially what you posted in your first post (with the added r_num column) and the main request is essentially the same as in response #1.

    But why would you do something like that?  View online or GROUP BY allows all.  If you remove them, you get the #1 response solution.

  • HP 5200 - print all of the pages that overlap on the first page

    I'm having a problem with one of my users while trying to print on our 5200 s HP.

    This just started happening today and not affect any other users who also use printers.

    When the user prints a document of several pages, it prints all the pages on a single page with all the text overlapping. Here is what I tried so far to fix it, nothing helps:

    -Other models HP print very well

    -Other profiles on the same PC with the same problem

    -J' changed the processor to "Winprint" - no luck

    -Update the driver does not

    -Remove the checkbox for 'Enable advanced features' doesn't fix it.

    -J' removed all traces of the printer in the registry and it still does the same thing.

    Help, please!

    It seems that if I use the 64-bit of Windows xp for the printer driver it solves the problem.

    Thanks for nothing, everybody.

  • Improve the performance of the MCs that overlap?

    I'll have some performance issues in some areas from Im flash game production.

    Here's the situation:

    I have a large movieclip containing a map that may be subject of a scrolling and scaling. There are panels with a bunch of MC buttons, controls, etc. on the right side of the scene. These are separate from the card and stay in the same place.

    Everything works fine until the large map is zoomed or scrolls such as the right buttons and things are overlapping their card. Then the framerate jumps down to a nice smooth 30 frames per second for about 3 fps while the map moves. There is no problem with the card move when they do not overlap.

    Now, the thing is, is that there is no real interaction between the buttons and the map. No transparency or whatever it is, in fact, I'm perfectly happy with the card to disappear behind a side panel. There are only about 3 panels that screen drawing routine would have to worry about, like all the buttons to rest on top of the panels, so why my performance takes such a success?

    (Hmmm. I have actually a lot of transparency, but each is on a University background, and no interaction with the map.)

    When no scaling (or discoloration or rotation etc), select your movieclips cacheAsBitmap property.  Disable when scaling (etc.).

  • Harvest of the bitmaps that overlap

    Fireworks can cut/merge the way overlapping objects as shown here:

    2009-09-21_1655.png

    Is this also possible with * bitmaps *? SE not with Fireworks CS4, then in PS CS4?

    This application is:

    2009-09-21_1657.png

    I have several bitmap to transparency reduction objects. But I don't want to let the underlying objects to shine through the overlying bitmap to the window. That is why I want to reframe the underlying windows with the overlying form of windows.

    Your help would be very appreciated.

    If the blue background is a solid color, just set the transparency of your bitmaps on the opaque rectangles, which look exactly like the background.

    If the background is not a solid color, then the mask technique will work fine. Apply the mask completely opaque to the fully opaque bitmap, then set the transparency on the compound object that results. I can't insert my image for example today, so I downloaded on my drop.io:

    http://drop.IO/FWpixlor/asset/maskfade-PNG

    It is a document of fireworks .png, so you can see how it works.

    If this is not the effect you are going for, then I'm afraid, that I do not understand your question.

  • update of the end date on the dates that overlap

    Hello
    I have this situation

    Status start_date end_date
    OP 1 January 2007 31 - dec - 2099
    W1 01-apr-2007 30-sep-2008
    October 1, 2008 31 - dec - 2099 W2
    W3 1 January 2009 31 - dec - 2010
    January 1, 2011 31 - dec - 2099 W4

    the December 31, 2099 end_date "is a conventional date and indicating the valid (current) state that should be the last"

    I want to update the value of the end date to the same value as the date of the next valid record

    result

    Status start_date end_date
    OP 1 January 2007 31 - mar - 2007
    W1 01-apr-2007 30-sep-2008
    October 1, 2008 31 - dec - 2008 W2
    W3 1 January 2009 31 - dec - 2010
    January 1, 2011 31 - dec - 2099 W4

    Any help?
    Thanks in advance
    lukx

    Hello

    Here's a way to do it:

    MERGE INTO     table_x          dst
    USING     (
              SELECT     start_date          -- or primary key
              ,     LEAD (start_date) OVER (ORDER BY start_date)
                        - 1     AS end_date
              FROM     table_x
         )               src
    ON     (src.start_date     = dst.start_date)     -- or primary key
    WHEN MATCHED THEN UPDATE
    SET     dst.end_date     = src.end_date
    WHERE     src.end_date     IS NOT NULL
    AND     end_date     = DATE '2099-12-31'     -- if wanted
    ;
    

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

  • Traffic that overlap on the device with the power of fire

    Hello world

    How should I handle the traffic that overlap on the device of firepower?

    I am inspection 2 VLANS using switches virtual, one VLAN is my edge of the internet and the other VLAN is my internal servers VLAN.

    Sometimes my internal servers to THAT VLAN needs access to internet and that traffic is superimposed on the inspection of my internet edge VLAN.

    Is there a configuration to avoid connections between connected/inspected twice?

    Thank you

    Hello

    You can create rule of the trust with areas / vlan specific or IP source/destination if you want a specific traffic does not inspect.

  • 5.5 Web client, right-click in Chrome now very boring with a menu that overlap, barely usable

    My setup is vSphere 5.5 with latest edition ESXi/Vcenter, and I use Google chrome 49.0 both 45.0 Firefox on my Windows 7 computer. Recently, some change has happened to Google chrome, making it extremely annoying. Please see the photo. Notice that eventually (it started to appear on April 5), every time I'm with the right button of the mouse, a window overlapping menu web client appears, preventing me from accessing some menu web client, I tried to solve this problem by selecting 'Settings' and disable flash related things (for example access flash to the camera privacy, etc.).  How can you get rid of the menu circled in red?

    Also Firefox's question, I use 4K monitor, the web client window is very small and cannot be changed even if I have the window zoom to 250-300%, no difference.

    Untitled.jpg

    Here's how I solved the problems for these who can use Firefox, I suggest that you switch to Firefox and install Adobe flash, it's difficult for me because the last Flash on Firefox does not the web interface to scale correctly on my 4K monitor, everything seems tiny.

    (1) uninstall Google chrome,

    (2) download old version of Google chrome by visiting this site:

    Download Google Chrome 46.0.2490.80 (Enterprise version for Windows - OldVersion.com

    (3) after the installation, turn off the update of Google chrome auto, here's the info:

    Disable updates of Chrome - Super user

    It will be implicitly security once you disable Chrome/flash update, if someone else finds the best solution, do not hesitate to add your opinion here.

    Update: this evening, the flash inside my google chrome (still in version 46.0.2490.80) is updated to the latest edition, automatically, I have no way to prevent this.    Now, when I use Google chrome, the annoying menu disappeared, I tried the same thing on my laptop, which hosts the last Chrome and Flash, the menu that overlap also disappeared, I wonder why?  This pi * s me off.

  • Leaves that overlap

    Hello

    I need to prepare a request for the removal of the leaves that overlap to a denunciation of employee leave and return leaves without records with overlap. It works well in cases where leave overlapps leave immediately above or below the recording of leave sorting based from the date as below:
    with t as
    (
    select 1 employee_num, to_date('01.09.2008','dd.mm.yyyy') gone_effdt,  to_date('29.10.2008','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('29.10.2008','dd.mm.yyyy') gone_effdt,  to_date('29.04.2009','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('29.04.2009','dd.mm.yyyy') gone_effdt,  to_date('01.05.2009','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('01.06.2009','dd.mm.yyyy') gone_effdt,  to_date('01.07.2009','dd.mm.yyyy') return_effdt from dual
    )
    SELECT employee_num,MIN(gone_effdt) gone_effdt,MAX(return_effdt) return_effdt
            FROM 
                (SELECT employee_num, gone_effdt, return_effdt,MAX(rn) OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt) max_rn
                 FROM   (
                        SELECT a.*,
                        CASE WHEN lag(return_effdt) OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt) < gone_effdt
                        OR
                        lag(return_effdt) OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt) IS NULL
                        THEN ROW_NUMBER() OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt)
                        END rn
                        FROM T a
                )       )
        GROUP BY employee_num, max_rn 
        ORDER BY gone_effdt;
    The above code returns a correct as result:
    EMPLOYEE_NUM     GONE_EFFDT     RETURN_EFFDT
    1                     01.09.2008     01.05.2009
    1                     01.06.2009     01.07.2009
    However, the logic above does not work for the data below where the overlap follows a different as model below:
    with t as
    (
    select 1 employee_num, to_date('01.09.2008','dd.mm.yyyy') gone_effdt,  to_date('29.10.2008','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('05.11.2008','dd.mm.yyyy') gone_effdt,  to_date('11.02.2009','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('29.10.2008','dd.mm.yyyy') gone_effdt,  to_date('29.04.2009','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('29.04.2009','dd.mm.yyyy') gone_effdt,  to_date('01.05.2009','dd.mm.yyyy') return_effdt from dual
    )
    SELECT employee_num,MIN(gone_effdt) gone_effdt,MAX(return_effdt) return_effdt
            FROM 
                (SELECT employee_num, gone_effdt, return_effdt,MAX(rn) OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt) max_rn
                 FROM   (
                        SELECT a.*,
                        CASE WHEN lag(return_effdt) OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt) < gone_effdt
                        OR
                        lag(return_effdt) OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt) IS NULL
                        THEN ROW_NUMBER() OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt)
                        END rn
                        FROM T a
                )       )
        GROUP BY employee_num, max_rn 
        ORDER BY gone_effdt;
    This gives the output as:
    EMPLOYEE_NUM     GONE_EFFDT     RETURN_EFFDT
    1                     01.09.2008     29.04.2009
    1                     29.04.2009     01.05.2009
    so in fact the result should be as below:
    EMPLOYEE_NUM     GONE_EFFDT     RETURN_EFFDT
    1                     01.09.2008     01.05.2009
    Kindly help with pointers to the achievement of the above output.

    Thanks in advance.

    How about this?

    with t as
    (
    select 1 employee_num, to_date('01.09.2008','dd.mm.yyyy') gone_effdt,  to_date('29.10.2008','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('05.11.2008','dd.mm.yyyy') gone_effdt,  to_date('11.02.2009','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('29.10.2008','dd.mm.yyyy') gone_effdt,  to_date('29.04.2009','dd.mm.yyyy') return_effdt from dual
    union all
    select 1 employee_num, to_date('29.04.2009','dd.mm.yyyy') gone_effdt,  to_date('01.05.2009','dd.mm.yyyy') return_effdt from dual
    )
    SELECT employee_num,MIN(gone_effdt) gone_effdt,MAX(return_effdt) return_effdt
            FROM
                (SELECT employee_num, gone_effdt, return_effdt,MAX(rn) OVER (PARTITION BY employee_num ORDER BY gone_effdt, return_effdt) max_rn
                 FROM   (
                        SELECT a.*,
                        CASE WHEN lag(maxdt) OVER (PARTITION BY employee_num ORDER BY gone_effdt, maxdt) < gone_effdt
                        OR
                        lag(maxdt) OVER (PARTITION BY employee_num ORDER BY gone_effdt, maxdt) IS NULL
                        THEN ROW_NUMBER() OVER (PARTITION BY employee_num ORDER BY gone_effdt, maxdt)
                        END RN
                        FROM (SELECT employee_num, gone_effdt, RETURN_EFFDT, MAX(RETURN_EFFDT) OVER (PARTITION BY employee_num ORDER BY GONE_EFFDT) maxdt FROM T) a
                )       )
        GROUP BY EMPLOYEE_NUM, MAX_RN
        ORDER BY GONE_EFFDT;
    

    But I suspect that there is a simpler solution (probably as suggested above marwin)

  • A TimeSpan that overlap

    Hi, I need to calculate the exact overlap between two battered.
    Main period = 2008-01-01 to 2008-01-15
    
    
    Overlapping periods:
    1 = 2007-12-28 to 2008-01-02
    2 = 2008-01-03 to 2008-01-12
    3 = 2008-01-14 to 2008-02-02
    I first check if there is no present overlap:
    SELECT * FROM periods WHERE periods.START > main_period.STOP AND periods.STOP < main_period.START;
    How can I get the timespan that overlap (in days) for the periods found and the main_period?

    If I have my right logic, something like that...

    NB. table m = main period, table o = overlapping periods

    SQL> ed
    Wrote file afiedt.buf
    
      1  with m as (select to_date('2008-01-01','YYYY-MM-DD') as dt_from, to_date('2008-01-15','YYYY-MM-DD') as dt_to from dual)
      2      ,o as (select to_date('2007-12-28','YYYY-MM-DD') as dt_from, to_date('2008-01-02','YYYY-MM-DD') as dt_to from dual
      3       union select to_date('2008-01-03','YYYY-MM-DD') as dt_from, to_date('2008-01-12','YYYY-MM-DD') as dt_to from dual
      4       union select to_date('2008-01-14','YYYY-MM-DD') as dt_from, to_date('2008-02-02','YYYY-MM-DD') as dt_to from dual)
      5  -- End of Test Data
      6  SELECT m.*, o.*, least(o.dt_to, m.dt_to) - greatest(o.dt_from, m.dt_from)+1 as overlap
      7  FROM o, m
      8* WHERE o.dt_from < m.dt_to AND o.dt_to > m.dt_from
    SQL> /
    
    DT_FROM   DT_TO     DT_FROM   DT_TO        OVERLAP
    --------- --------- --------- --------- ----------
    01-JAN-08 15-JAN-08 28-DEC-07 02-JAN-08          2
    01-JAN-08 15-JAN-08 03-JAN-08 12-JAN-08         10
    01-JAN-08 15-JAN-08 14-JAN-08 02-FEB-08          2
    
    SQL>
    

    If the first row overlaps the 1st and 2nd Jan that is 2 days
    The second row overlaps on everything, that is days from 3rd to 12th jan for example 10 days
    and the third row overlaps the 14 and 15 Jan that is 2 days.

Maybe you are looking for

  • Why can't connect on YouTube using firefox.

    I can open YouTube videos, but I can't log in on my account. I deleted all my cookies and have updated all my plugins (java and adobe were obsolete).

  • Tecra 8100 Selectbayproblem

    Hello, does anyone know how the Tecra checks closed Selectbay? I did some maintanence on mine and since then it will not start, when I press the power button the "On" - Led goes on and so did led the Selectbay, besides locking digital led flashes onc

  • Satellite A210-1AO does not start

    Hello I could use a little help. My 4 year old A210 1AO worked perfectly until today (except to change the HARD disk a few months before). Tonight, I tried to turn it on, but almost nothing happens. The light 'on' is on, the battery the power and lig

  • I want to buy an iPhone that is from the United Kingdom, but I live in Lithuania - guaranteed?

    Hello, I had the opportunity to buy a new iPhone from Apple 6 from a person, but I live in Lithuania and that the phone is from the United Kingdom. How would it be with the guarantees? He said "guarantee international Apple from the moment wherever t

  • Netflix password

    Original title: forgotten password I forgot my password for netflix