Need to find gaps in the data

Hi all

I have the following documents:

-Drop Table
drop table agreement;
drop table GRP_INFO;
-Create table
create table agreement
(
Agreement_Id Number (5),
Date of Coverage_Effective_Date,
Date of COVERAGE_termination_date
);
Create Table GRP_INFO
(
Agreement_Id Number (5),
Grp_Id Number (5),
Date of Effective_Date,
Date TERMINATION_DATE
);
------------

-Insertion
Insert into the agreement
Select 100,'01 JAN - 2013", December 31, 2013"
From Dual;

Insert into the agreement
Select 200,'01 JAN - 2013", December 31, 2013"
From Dual;

Insert into the agreement
Select 300,'01 JAN - 2013", December 31, 2013"
From Dual;

Insert into the agreement
Select 400,'01 JAN - 2013", December 31, 2013"
From Dual;
----------
Insert into Grp_Info
Select 100.1, 1 January 2013 ", 31 March 2013"
Of the double
UNION ALL
Select 100.2, April 1, 2013 ", April 2, 2013"
Of the double
UNION ALL
Select 100.3, April 3, 2013 ", April 15, 2013"
Of the double
UNION ALL
Select 100.4, April 3, 2013 ", April 15, 2013"
Of the double
UNION ALL
Select 100.5, 1 June 2013 ", December 31, 2013"
Of the double
Union All
Select 200.6, 1 January 2013 ", April 2, 2013"
Of the double
Union All
Select 200,7, April 3, 2013 ", April 15, 2013"
Of the double
Union All
Select 200,8, April 3, 2013 ", April 15, 2013"
Of the double
Union All
Select 200,9, June 1, 2013 ", November 30, 2013"
Of the double
Union All
Select 300,10, 1 January 2013 ", April 15, 2013"
Of the double
Union All
Select 300,11, April 16, 2013 ", December 31, 2013"
Of the double
Union All
Select 400,12, January 2, 2013 ", December 31, 2013"
From Dual;

COMMIT;

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

-Queries on the table of the agreement

Select * agree;

-Result of the query

agreement_id coverage_effective_date coverage_termination_date

100                                         01-JAN-13                                                   31-DEC-13

200                                         01-JAN-13                                                   31-DEC-13

300                                         01-JAN-13                                                   31-DEC-13

400                                         01-JAN-13                                                   31-DEC-13

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

-Queries on grp_info table

agreement_id grp_id effective_date termination_date

100                                              1                     01-JAN-13                       31-MAR-13

100                                              2                     01-APR-13                       02-APR-13

100                                              3                     03-APR-13                       15-APR-13

100                                              4                     03-APR-13                       15-APR-13

100                                              5                     01-JUN-13                        31-DEC-13

200                                              6                     01-JAN-13                        02-APR-13

200                                              7                     03-APR-13                        15-APR-13

200                                              8                     03-APR-13                        15-APR-13

200                                              9                     01-JUN-13                         30-NOV-13

300                                              10                   01-JAN-13                         15-APR-13

300                                              11                   16-APR-13                         31-DEC-13

400                                              12                   02-JAN-13                          31-DEC-13

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

-Result

agreement_id

100

200

400

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

-Logic for the above result

Each agreement_id have several grp_id and grp_id all or at least one should cover all the period agreement_id for example:

-Agreement_id 100 a protection from the date is January 1, 2013 and coverage_termination_date is December 31, 2013, and if you look in all the archives against agreement_id 100 so you can find the period from April 16, 2013 until 31 May 2013 are missing so I need this agreement_id.

-Agreement_id 200 a protection from the date is January 1, 2013 and coverage_termination_date is December 31, 2013, and if you look in all the archives against agreement_id 200 then you can find that the period from December 1, 2013 until 31 December 2013 are missing so I need this agreement_id.

-Agreement_id 300 a protection from the date is January 1, 2013 and coverage_termination_date is December 31, 2013, and if you look in all the archives against agreement_id 300 then you can find that no period is missing, I don't need this agreement_id.

-Agreement_id 400 a protection from the date is January 1, 2013 and coverage_termination_date is December 31, 2013, and if you look in all the archives against agreement_id 300 then you can find that the period from January 1, 2013, until January 1, 2013 is missing, so I need this agreement_id.

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

Please let me know if you have any related questions my script and I really appreciate if someone can give me the solution for this problem.

Concerning

Line

Hello

Here's one way:

WITH got_gap AS

(

SELECT agreement_id, effective_date, termination_date

CASE

WHEN effective_date >

1 + MAX (termination_date) OVER (PARTITION BY agreement_id

ORDER BY effective_date

ROWS BETWEEN UNBOUNDED PRECEDING

AND 1 PRECEDING

)

THEN 1

Difference in the END as the

OF grp_info

)

SELECT g.agreement_id

OF got_gap g

JOIN agreement has ON a.agreement_id = g.agreement_id

GROUP BY g.agreement_id

GIVEN the NUMBER (g.gap) > 0

MIN (g.effective_date) OR > MIN (a.coverage_effective_date)

OR MAX (g.termination_date)< max="">

ORDER BY g.agreement_id

;

Output:

AGREEMENT_ID

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

100

200

400

Makes no assumptions about effective_date and termination_date, except that effective_date<= termination_date="" on="" each="" row. ="" it's="" okay="" if="" different="" rows="" for="" the="" same="" agreement_id="" overlap,="" or="" if="" one="" encompasses="">

Do not attempt to insert VARCHAR2 values (like January 1, 2013 "") in the DATE columns.  Use TO_DATE, either DATE literals.

Tags: Database

Similar Questions

  • [Bug]? Hypertrend attracts 'False' gaps in the data

    Hello

    I noticed Hypertrend drawing of gaps in the data (when it was actually data). This can be confirmed when you zoom in on the data. Is this a known problem, or is there no solution to workaround/configuration? The images are taken from Hypertrend in LabVIEW, but we saw in MAX too.

    See you soon

    -JG

    Here are some previous discussions on the subject...

    http://forums.NI.com/T5/real-time-measurement-and/distributed-system-manager-historical-trend/m-p/99...

    Also see the attachment for a video of Jing of the problem.  This happens in DSM 2009 and 2010 and on several machines.

    Here is the final result after much rangling with OR:

    From: Mark Black [mailto:[email protected]]
    Sent: Thursday, January 21, 2010 16:53
    To: Sachs, Michael a. (MSFC-ET30) [Intelligent Systems]
    CC: Roger Hebert
    Subject: Re: questions of DSM

    Hi Mike,.

    We do not have a CAR for the same problem (#178809), but this is a general CAR for these types of Hypertrend issues of drawing that matches your case in. This bug is not currently targeted to be fixed for the SP1, but I got in touch with our team of development of Shanghai an update.  Have you seen this problem on several different systems?  Have you seen this problem with plots that are not related to your GPS synchronized cRIO?

    Thank you
    Black mark
    Product Support Engineer - LabVIEW R & D
    National Instruments
    [email protected]
    (512) 683-8929

  • Find files on the data store that have been removed from inventory, but not deleted from the disk

    I have ESXi 4.1 and with vSphere Client to manage virtual machines.

    Some of my users continue to use the 'remove from inventory"rather than the option" remove disc "in vSphere when they want to delete the virtual machine.

    This leaves the computer virtual on the data store but not used. I have since removed this privilege among the offending users but I need to do a bit of cleaning.

    I have a lot of files on the data store where users have done this in recent years. Probably about 150 records but only 80 VM listed in the inventory.

    Is there a way I can output, a report showing the data of each machine store directory in inventory so that I can remove anything not on this list? ID rather not to manually check the parameters of all 80 VM in the inventory.

    Out ideal would be something like:

    MyVmNameHere 1, \MyVmDirectoryHere1\ [DataStore1]

    MyVmNameHere2, \MyVmDirectoryHere2\ [DataStore1]

    A great tool to discover all this and much more is RVTools

    André

  • I need to find all of the XML elements and add a line break for the text of each of them

    I need to find all XML elements and to add a line break the text of each of them.

    Is it possible with a script?

    Try this piece of code as it is. I hope that's what you want...

    var myDoc = app.activeDocument;
    var inddRooElement = myDoc.xmlElements.item(0);
    var xPathElements = inddRooElement.evaluateXPathExpression("//*");
    var elementCount = xPathElements.length;
    for(var eId=0; eId
    

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

    Green4ever

  • Need help with XML, view the data by scanning/click

    Hello.

    I am creating a moibile app that displays XML data. It is a telephone directory. I want the data to change when we slide. I can get the data very well. I can get it to display fine. I do not see the correct image first, however. I think it's a problem with my imagenum variable.

    Then, I want to change what is displayed when the user clicks/slide on the screen. How do I do that?

    Stop();
    var nameArray:Array = new Array();
    var countryArray:Array = new Array();
    var portraitArray:Array = new Array();
    var flagArray:Array = new Array();
    var jobtitleArray:Array = new Array();

    var imageNum:Number = 0;
    var totalImages:Number;

    Loading XML
    var XMLURLLoader:URLLoader = new URLLoader();
    XMLURLLoader.load (new URLRequest ("recbook.xml"));


    XMLURLLoader.addEventListener (Event.COMPLETE, processXML);


    function processXML(event:Event):void {}

    var theXMLData:XML = new XML (XMLURLLoader.data);
    totalImages = theXMLData.name.length ();
    for (var i: Number = 0; i < totalImages; i ++) {}
    Data in the tables xml push
    nameArray.push (theXMLData.name [i]);
    countryArray.push (theXMLData.country [i]);
    portraitArray.push (theXMLData.portrait [i]);
    flagArray.push (theXMLData.flag [i]);
    jobtitleArray.push (theXMLData.jobtitle [i]);
    }
    the data is processed

    loadData();
    }

    function loadData (): void {}

    var thisPortrait:String = portraitArray [imageNum];
    var thisCountry:String = countryArray [imageNum];
    var thisName:String = NomTableau [imageNum];
    var thisJobtitle:String = jobtitleArray [imageNum];
    var thisFlag:String = flagArray [imageNum];

    var dataLoader:Loader = new Loader();
    dataLoader.load (new URLRequest (portraitArray [imageNum]));
    dataLoader.contentLoaderInfo.addEventListener (Event.COMPLETE, dataLoaded);
    function dataLoaded(event:Event):void {}

    I want to start with 0 (img1.jpg) image and scroll with a click of the mouse (finger on iOS kick)
    stage.addEventListener (MouseEvent.CLICK, loadMainImage1);
    function loadMainImage1(event:MouseEvent):void {}
    portraitUILoader.source = thisPortrait;
    flagUILoader.source = thisFlag;
    selectedName.text = thisName;
    selectedCountry.text = thisCountry;
    selectedJobtitle.text = thisJobtitle;
    }
    }

    Add to imageNum (1);
    imageNum ++;
    If (imageNum < totalImages) {//stopping to img2
    trace ("imageNum" + imageNum);
    trace ("name of the image (tomyline)" + tomyline "); losing picture 4 somewhere

    loadData();
    }

    trace ("Total Images" + totalImages);

    }

    Click here to pass the screenI House would this gap. do not know how.
    homeScreen_mc.addEventListener (MouseEvent.CLICK, goNext);

    function goNext(event:MouseEvent):void
    {
    nextFrame();
    }


    * / Here is the result:
    imageNum 1
    image name (tomyline) images/img1.jpg
    imageNum 2
    image name (tomyline) images/img2.jpg
    imageNum 3
    image name (tomyline) images/img3.jpg
    Total of 4 Images
    Total of 4 Images
    Total of 4 Images
    Total of 4 Images

    It starts on frame 1 display (the second in the series img2.jpg) * /.

    If (imageNum< totalimages)="" {//stopping="" at="">
    trace ("imageNum" + imageNum);
    trace ("name of the image (tomyline)" + tomyline "); losing picture 4 somewhere
    imageNum ++;
    If (imageNum! = totalImages) loadData();
    }

  • Why I need to_char allows to compare the date?

    Hi guys:

    I have a question that seem silly, but I couldn't know.

    I have a simple query on Oracle 11 G R2 and I use SQL developer 3.1.07, the schema and the data has been migrated from a SQL Server:
    select *
    from vernote 
    where whendate='09-JUL-12';
    It returns empty results. However, tuples are in the table. When I try this:
    select *
    from vernote 
    where to_char(whendate)='09-JUL-12';
    He returned 677 lines. the whendate data type is date. but when I try another table in the same pattern:
    select *
    from invoices
    where transpostdate='09-JUL-12';
    It returns tuples, and I don't have to use the function to_char. transpostdate is also a date. Could someone tell me why the two columns: whendate, transpostdate both are of type date, but I have to use to_char to compare, the other does not?

    Thanks in advance!

    Sam

    lxiscas wrote:
    Hi guys:

    I have a question that seem silly, but I couldn't know.

    I have a simple query on Oracle 11 G R2 and I use SQL developer 3.1.07, the schema and the data has been migrated from a SQL Server:

    select *
    from vernote
    where whendate='09-JUL-12';
    

    It returns empty results. However, tuples are in the table. When I try this:

    select *
    from vernote
    where to_char(whendate)='09-JUL-12';
    

    He returned 677 lines. the whendate data type is date. but when I try another table in the same pattern:

    select *
    from invoices
    where transpostdate='09-JUL-12';
    

    It returns tuples, and I don't have to use the function to_char. transpostdate is also a date. Could someone tell me why the two columns: whendate, transpostdate both are of type date, but I have to use to_char to compare, the other does not?

    Thanks in advance!

    Sam

    What kind of data are WHENDATE & TRANSPOSTDATE?

    If they are the data type DATE, then they contain data too part TIME.
    NEVER rely on the implicit data type conversion.
    July 9, 12 ' is STRING; not a DATE

    When TRUNC (transpostdate) = TO_DATE('09-JUL-2012','DD-MON-YYYY');

  • Need to request so that the data dictionary

    Hi all

    I need an application that can show all the details of the tables in my database

    request to see the... : table name, type of name of column data, constraints, default value, etc...

    I found two tables in the database that showa all this information... Here are the 2 quiries:

    Select table_name, column_name | » ('|| DATA_TYPE | (' ('| data_length |')) "column_name from all_tab_columns

    where OWNER = "UBSPROD."

    Select constraint_name, constraint_type, table_name, search_condition_vc, index_name

    From user_constraints where owner = "UBSPROD";

    but when I join them I get a lot of records... I mean I think he's going to cartiantion products

    I used query below:

    Select at.table_name, at.column_name |' ('| at.data_type |') ('|| at.data_length||')) "column_name,
    UC.constraint_name, uc.constraint_type, uc.table_name, uc.search_condition_vc, uc.index_name from all_tab_columns to, uc user_constraints
    where at.owner = 'UBSPROD. '
    and at.table_name = uc.table_name

    Please, help me to display information with all tables of database related...

    Thank you

    The reason you see too many lines is because one table lists columns and a list of constraints and want to join the table name. So if you have a table with 3 constraints and 5 columns, you get 15 lines, which probably makes no sense.

    Have a reflection on what data you actually want to display for each table. There is a many-to-many relationship between columns and constraints (each column can contain zero or more constraints, each constraint can use more than one column), is without doubt better to keep the two separate, for example

    COL1

    COL2

    COL3

    COL4

    COL5

    CONSTRAINT1

    CONSTRAINT2

    CONSTRAINT3

    This would be achieved either with two separate queries, or you can use a UNION ALL operation, as appropriate. If you want to display the columns used in a constraint, you must query the synonym ALL_CONS_COLUMNS.

    Also, make sure you are compatible by using the ALL_ or synonyms USER_ - do not mix the two.

  • How can I find what is the data type of a column of a Table in oracle or SQL?

    (a) what happens if I want to know the type of data in a specific column in the Table.

    (b) how to find the column data types?

    Can someone help me please. I am new to oracle and try to learn a few tricks

    Hello

    How to do

    SQL > desc

    SQL> desc emp
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     EMPNO                                     NOT NULL NUMBER(4)
     ENAME                                              VARCHAR2(10)
     JOB                                                VARCHAR2(9)
     MGR                                                NUMBER(4)
     HIREDATE                                           DATE
     SAL                                                NUMBER(7,2)
     COMM                                               NUMBER(7,2)
     DEPTNO                                             NUMBER(2)
    
  • Find records in the date range

    Hello

    I have the following data
    with t as (
       select 1234 prod_id, to_date('01-Jan-2008', 'dd-MON-yyyy') start_date, to_date('01-May-2012', 'dd-MON-yyyy') end_date
        from dual union 
        select 4567 prod_id, to_date('01-Aug-2007', 'dd-MON-yyyy') start_date, to_date('01-Apr-2012', 'dd-MON-yyyy') end_date
        from dual union
        select 8910 prod_id, to_date('01-Jul-2006', 'dd-MON-yyyy') start_date, to_date('01-Mar-2012', 'dd-MON-yyyy') end_date
        from dual 
        )      
        SELECT *
      FROM t
    What is the best way to find all records in April 1, 2012 and April 30, 2012?

    Concerning

    Assuming that you are looking for cumulation ranges

    SELECT *
      FROM t
     WHERE start_date BETWEEN date '2012-04-01' and date '2012-04-30'
        OR end_date BETWEEN date '2012-04-01' and date '2012-04-30'
        OR (    start_date < date '2012-04-01'
            AND end_date > date '2012-04-30' )
    

    who produces the two lines expected

    SQL> with t as (
      2     select 1234 prod_id, to_date('01-Jan-2008', 'dd-MON-yyyy') start_date, to_date('01-May-2012', 'dd-MON-yyyy') end_date
      3      from dual union
      4      select 4567 prod_id, to_date('01-Aug-2007', 'dd-MON-yyyy') start_date, to_date('01-Apr-2012', 'dd-MON-yyyy') end_date
      5      from dual union
      6      select 8910 prod_id, to_date('01-Jul-2006', 'dd-MON-yyyy') start_date, to_date('01-Mar-2012', 'dd-MON-yyyy') end_date
      7      from dual
      8      )
      9  SELECT *
     10    FROM t
     11   WHERE start_date BETWEEN date '2012-04-01' and date '2012-04-30'
     12      OR end_date BETWEEN date '2012-04-01' and date '2012-04-30'
     13      OR (    start_date < date '2012-04-01'
     14          AND end_date > date '2012-04-30' );
    
       PROD_ID START_DAT END_DATE
    ---------- --------- ---------
          1234 01-JAN-08 01-MAY-12
          4567 01-AUG-07 01-APR-12
    

    Justin

  • Find days between the dates expressed in days.

    Hi, I have a table with a structure similar to the following:

    LP1 TIME_EQ P_DAY LP2
    17.2

    0

    MONDAY
    16.8

    0.25

    TUESDAY
    17.03.5THURSDAY
    17.75FRIDAY
    17.41FRIDAY
    16.9.25SATURDAY
    17.1.25SATURDAY
    17.5SUNDAY

    Now I have two variables dates D1 = October 10, 2013 (Thursday) and D2 = 13 October 2013 (Sunday).

    How do I change my table such as only the lines covered between dates D1 and D2 are updated? In this case, the lines where the P_DAY (Thursday, Friday, Saturday, Sunday) I will use it for my slider, my query begins with this:

    CURSOR LOAD_PROF is

    SELECT LP1, TIME_EQ, P_DAY

    DE LOAD_PROFILE_TEST

    P_DAY in (? days between D1 and D2).

    I hope you get my point.  Thank you.

    First impression is that your table design seems incorrect to me. Why just store DAY? Why not the whole date?

    Says you can do this

    Select lp1

    time_eq

    p_day

    of load_profile_test

    where p_day in)

    Select to_char (start_date + (level 1), "fmDAY") day_

    de)

    Select to_date (October 10, 2013 ',' mon-dd-yyyy "") start_date

    , to_date (13 October 2013 ',' mon-dd-yyyy "") end_date

    of the double

    )

    connect

    by level<=  end_date="" -="" start_date ="" +="">

    )

    And finally the cursor? Try to do so in direct SQL. Do not loop through a cursor. If you share this part, we can give you best suggestion on the implementation of your real problem.

  • Where can we find out about the date and time for rollback on Oracle 11 g?

    Want to know what Oracle written paper in order to store information on the restoration that is executed. I have a question in which, according to me, a cancellation has occurred once external reports have been generated... therefore, the report has more accurate information on the State of the system. However, I have to confirm that this is what has happened, that I could not explain why the transactions that were performed before the reports were not on the system, but it was reported in the transaction report. Thank you.

    You should be able to find some information of restoration in recovery with LogMiner newspapers: http://download.oracle.com/docs/cd/E11882_01/server.112/e17110/dynviews_2035.htm#i1408263.

  • need to find and change the connection speed

    I take a class online and when I ran the test of the pre-class, the report said my connection on the modem speed speed but must be something else. How can I fix it?

    I take a class online and when I ran the test of the pre-class, the report said my connection on the modem speed speed but must be something else. How can I fix it?

    Hey cherokeegirl507

    Contact your internet service provider

    They provide your broadband or dial-up connection

    discuss with them ways to achieve best download speed plan them and or what is required by your class online

    and also to discuss with the people who run the online class

    Walter, the time zone traveller

  • Profile Palm site should be easier to find, should list the date of the last synchronization, might allow that an export of contact information and help from backup should not give 404 s.

    I had to reset my phone last night, and neither I, nor the technology of Sprint knew where was the site of palm profile.  I finally found at palm.com, but perhaps the Palm profile on the phone itself should contain a URL or a help file on the phone in contacts AND backups...

    In any case, we went there just to confirm that the phone had recently sync would be and there is no information presented at palm.com concerning the status of the last synchronization.  I think there should be.

    Also, when in the backup application, I tried to read the help, I rather got a 404 help.palm.com/en-us/c019-00/d100-00/palm_activate/index.html

    or...

    Just go to www.palm.com/palmprofile

  • Windows Backup & restore leaves gaps in the backup period date ranges

    I noticed that backup & restore leaves gaps in the date ranges displayed on the screen of backup periods under the function to manage the space.  This means that files change during the interval periods have not been saved?  For example, the screen shows currently backups and the following periods:

    Jan 26: 12-18 Mar, 12 GB 10.40

    Apr 04, 12-13 Apr, 12 GB 19.62

    27 April, 12-27 Apr, 12 GB 05.16

    May 06,12 - May 06,12 02.41 GB

    May 27.12 - 17 Jun, 12 GB 03.41

    What is the importance of gaps?

    How can I tell that B & R is fully backup all files that changed since the last backup run?

    How can I varify the 1st backup is a backup full?

    How can I varify that the system image backup is up-to-date?

    I save approximately once a week to a USB external hard drive. I use options "Include a system image" and "Let me choose" to select the files and have selected the option 'keep only the last frame system & minimize the space used '.

    Hello

    Backups are created in sets called backup periods. To maximize your disk space, Windows backup backup all folders selected, the first time it's run and then it only backs up files that are new or have been modified since the last backup was made. Periodically, Windows creates a new, full backup. Each full backup is called in a backup. When you view your backups of files, you can see all the backup periods with date ranges. If you decide to delete backups of files, you should always keep the most recent backup of the file.

    Reference:

    Should what backup settings I use to maximize my disk space? http://Windows.Microsoft.com/en-us/Windows7/what-backup-settings-should-I-use-to-maximize-my-disk-space

    Back up and restore: frequently asked questions

    http://Windows.Microsoft.com/en-us/Windows7/products/features/backup-and-restore

  • I want out emails in folders of ordinary files, but when I drag-and-drop, the "modification date" gets changed. How I can still see the date?

    To archive my e-mail files until I decided to switch to Thunderbird, I create regular folders in windows and drag and drop emails to outlook express in the appropriate folders. The "update" column displays the original date of the email... which is what I want to do with Thunderbird. In my view, that he treats it as a new file created today... that is not good for my archiving system of these professional work files that I need to find often in approximate date.

    I understand the forum that it is by default in Thunderbird. There is an add-on that can do what I'm doing?

    Thank you in advance,
    Netwon

    I think the reason what OE is the original date because each message is stored in a single file, while TB stores all messages in a folder in a file, an mbox file. Thus, when you save a message as a single eml file, its 'modification date' corresponds to the eml file date was written in the mbox file.

    You can find the ImportExportTools add-on useful because it allows you to add the date of the e-mail eml file name when enamel is exported ("Save selected messages" of the message right-click menu).

Maybe you are looking for