Need to find out gap in data

Hi All
I have the following records:
--Drop Table
drop table agreement;
drop table GRP_INFO;
--Create table
create table agreement
Agreement_Id Number(5),
Coverage_Effective_Date Date,
COVERAGE_termination_date date
Create Table GRP_INFO
Agreement_Id Number(5),
Grp_Id Number(5),
Effective_Date Date,
TERMINATION_DATE Date
--Insertion
Insert Into Agreement
Select 100,'01JAN-2013','31-DEC-2013'
From Dual;
Insert Into Agreement
Select 200,'01JAN-2013','31-DEC-2013'
From Dual;
Insert Into Agreement
Select 300,'01JAN-2013','31-DEC-2013'
From Dual;
Insert Into Agreement
Select 400,'01JAN-2013','31-DEC-2013'
From Dual;
Insert Into Grp_Info
Select 100,1,'01-JAN-2013','31-MAR-2013'
From Dual
UNION ALL
Select 100,2,'01-APR-2013','02-APR-2013'
From Dual
UNION ALL
Select 100,3,'03-APR-2013','15-APR-2013'
From Dual
UNION ALL
Select 100,4,'03-APR-2013','15-APR-2013'
From Dual
UNION ALL
Select 100,5,'01-JUN-2013','31-DEC-2013'
From Dual
Union All
Select 200,6,'01-JAN-2013','02-APR-2013'
From Dual
Union All
Select 200,7,'03-APR-2013','15-APR-2013'
From Dual
Union All
Select 200,8,'03-APR-2013','15-APR-2013'
From Dual
Union All
Select 200,9,'01-JUN-2013','30-NOV-2013'
From Dual
Union All
Select 300,10,'01-JAN-2013','15-APR-2013'
From Dual
Union All
Select 300,11,'16-APR-2013','31-DEC-2013'
From Dual
Union All
Select 400,12,'02-JAN-2013','31-DEC-2013'
From Dual;
COMMIT;
--Query on agreement table
Select * from Agreement;
--Query Result
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
--Query 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 multiple grp_id and all grp_id or atleast one should cover all period agreement_id for example:
- Agreement_id 100 has coverage effective date is 01-Jan-2013 and coverage_termination_date is 31-Dec-2013 and if you look into all record against agreement_id 100 then you can find that the period from 16-Apr-2013 till 31-May-2013 are missing so I need this agreement_id.
- Agreement_id 200 has coverage effective date is 01-Jan-2013 and coverage_termination_date is 31-Dec-2013 and if you look into all record against agreement_id 200 then you can find that the period from 01-DEC-2013 till 31-DEC-2013 are missing so I need this agreement_id.
- Agreement_id 300 has coverage effective date is 01-Jan-2013 and coverage_termination_date is 31-Dec-2013 and if you look into all record against agreement_id 300 then you can find that no period is missing so I don't need this agreement_id.
- Agreement_id 400 has coverage effective date is 01-Jan-2013 and coverage_termination_date is 31-Dec-2013 and if you look into all record against agreement_id 300 then you can find that the period from 01-JAN-2013 till 01-JAN-2013 is missing so I need this agreement_id.
Please let me know if you have any questions related to my scenario and I really appreciate if someone provide me solution for this issue.
Regards
Shumail

Hi,
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
           END  AS gap
    FROM    grp_info
SELECT    g.agreement_id
FROM      got_gap g
JOIN      agreement a  ON  a.agreement_id = g.agreement_id
GROUP BY  g.agreement_id
HAVING    COUNT (g.gap)             > 0
OR        MIN (g.effective_date)    > MIN (a.coverage_effective_date)
OR        MAX (g.termination_date)  < MAX (a.coverage_termination_date)
ORDER BY  g.agreement_id
Output:
AGREEMENT_ID
         100
         200
         400
This 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 another.
Don't try to insert VARCHAR2 values (such as '01-JAN-2013') into DATE columns.  Use TO_DATE, or DATE literals.

Similar Messages

  • How do I find out the purchase date of my MacBook Air?

    I need to find out the purchase date of my MacBook Air so I can register it as a product in my Apple ID. I bought the MacBook from a friend, and he doesn't remember the date it was purchased on.

    Giving away / Selling your Mac / Resetting  the computer to the factory condition
    http://support.apple.com/kb/HT5189
    http://www.thesafemac.com/how-to-prepare-your-mac-for-sale/

  • I am working in Adobe Acrobat 9 Pro and just created a pdf form from a MS Word document. I need to find out how to have a date field in my form which will update automatically. Can some one out there help me?

    I am working in Adobe Acrobat 9 Pro and just created a pdf form from a MS Word document. I need to find out how to have a date field in my form which will update automatically.

    Update automatically under which circumstances, exactly?

  • I need to find out how much wifi data my apps are using. I have a very limited amount of wifi data, and I am exceeding my monthly allowance. Apparently, even apps I think are not open are sending/receiving data through the wifi and using up my allowance.

    I need to find out how much wifi data my apps are using. I am on a very limited amount of WiFi data each month, which I am regularly exceeding. I have been told to work out which of my apps is using the data. Also, I think I have closed an app by double clicking the home button, then swiping the app up - is this the way to close it, or will it still be sending/receiving data?

    Go into your Settings : General : and turn off background refresh for your apps.  In Settings : Mail  turn Fetch new data to OFF and Load Remote Images to OFF.  This will mean that Mail will only check for messages when you actually use it, and all your advertising junk mail won't have all the images in it.
    Turn off push notifications every chance you get.
    Make sure you are actually quitting apps:  to quit apps press the Home button twice and you should see a bunch of smaller screen images for every open app.  To quit the app swipe from the screen image (not the icon) upward off the top of the iPad.  You can swipe left and right to see more open apps, but there must be no left-right movement on the screen when you swipe upward to close the app.
    Turn off your internet connection when you do not need it.  The easiest way to do this is to swipe up from the bottom of you screen to get the control centre, and then touch the airplane to turn on airplane mode.  You can repeat this sequence to turn it back on again when you need it.  Most especially turn airplane mode on whenever you are sleeping your iPad for long periods.  This will save battery life too.  OR actually turn your iPad off - which means holding the power key down for several seconds until the red swipe bar appears, and then swipe to turn it off.  If you go this route, note that it will take longer to turn on then it takes to wake from sleep.

  • Need to find out the number of Master data records transfered to the BW

    Hi,
    We need to find out the number of Master data (example -0MAT_PLANT_ATTR) records to be transfered to BW side. This is a delta extract.  We are preparing test scripts to check the master data extract ( full & delta) from ECC6 TO BI 7.0..
    Advance Thanks.

    Hi,
    Goto RSA3 and run that master data extractor in D mode if you want to know the number of records in delta and in F mode if you want to know the Full volume. But make sure that you set data records/calls and the display extr calls numbers so that you get the total number of records.
    The other option is goto the master data source table and look at the number of records in that table. That'll give you an idea of the total number of records in the table.
    One other option is to goto RSA7 , select the delta datasource and hit the display button. You'll get to know the number of entries in the delta queue that way as well.
    Cheers,
    Kedar

  • Need to find out how to lock a point in a path that will not allow the rest of the path to rotate or move around it

    Hello,
    I am having some trouble with using shape layers and paths to create a solid, flat 'hair' effect in a cartoon animation.
    I have used a semicircle shape layer as the hair on the head itself and then a path with a stroke of the same width as the semi circle to be the long part of the hair.
    Unfortunately when I move/rotate the bottom point in the path it causes gaps to appear further up where the stroke is rotating around the point at which the stroke is supposed to "connect" to the semi circle.
    I have included a couple of screenshots of me rotating the hair opposite ways so you can see.
    - imgur: the simple image sharer
    - imgur: the simple image sharer
    I need to find out if there is a way to lock the top point in place where it joins the semi circle blond hair which will stop this part from moving at all, even rotating around the point.
    But the bottom needs to move freely and obviously the part between the two points will move fairly naturally.
    If you can imagine how a girl with long hair has her hair attached to her head, it does not move at all, but the bottom moves freely. It needs to be like this.
    If you can provide any assistance it would be greatly appreciated.
    Thanks!

    That is perfect thank you so much!
    Can't believe I didn't think of that but you da real MVP!

  • How to find out the "manufacture date"?

    Hello!
    Can you tell me how to find out the manufacture date of my Satellite A110-334 with the serial "SY6224123K"?
    I need this information for my insurance!
    I found only this link for HDD`s: http://www.storage.toshiba.eu/index_manual.php?pid=220&sid=536&la=en
    But there is no "S" on the first digit!??
    So it is maybe "Y6" which can be November 2006! Is this right?
    Thank you!
    ===========
    This is the information on the link above:
    How to encode a Toshiba Hard Disk Drive Serial Number?
    The Toshiba serial number (S/N) includes details of the date of manufacture. The first digit of the serial number indicates the Month of manufacture and the 2nd digit indicates the Year.
    Example:
    M Y x x x x x x x
    M = Month
    Y = Year
    The month digit goes from 1, for January, through to 9, for September, and then X, Y and Z, for October, November and December.
    Examples:
    2 8 1 7 0 0 0 1 A
    2 = February
    8 = 1998
    3 0 5 4 4 3 0 6 T
    3 = March
    0 = 2000
    X 9 D 7 8 3 3 1 T
    X = October
    9 = 1999
    The remaining digits contain information about factory and production line, and some digits are reserved for a continuously running serial number.

    Hello
    Try with http://gedb.toshiba.com/
    Let me know if you find info you need.

  • I need to find out  the  list of outbound made it  to the vendor

    I need to find out if the attached list of outbound  made it  to the vendor.
    and i have  list of all IDOC numbers that i need to check.  Could you please assist? how to check?
    Please do needful.
    Thanks in advance.
    Regards,
    PIneeder.

    Hi,
    If you want to check it in XI/PI check first:
    - in the abap stack transaction:
                  - sxmb_moni and filter for your sending system and idoc type
                         or
                  - idx5 fill in the date when the idoc was sent and the idoc number from the sending system and through double-clicking you will get to the same message as in sxmb_moni
    - in the runtime workbench (only if the communication with the partner is done via a java based adapter (all except xi,http and idoc) go to the runtime workbench and then click on message monitoring and filter for your messages. If the status there is succesfull then you can safely assume that the message was delivered to the partner. Note: it sometimes happens that a PI server also has one or more decentral adapter engines. In this case you need to check if your communication channel is deployed on any of them (you can check that in the Integration Builder) and then select the corresponding one in the Runtime workbench -> Message Monitoring -> Message from Component.
    Hope this helps,
    Horia

  • I need to find out dollar amount on iTunes "Give any amount" gift cards I purchased, store clerk did not write down the amounts

    I need to find out dollar amount on iTunes "Give any amount" gift cards I purchased at CVS, store clerk did not write down the amounts when I purchased.

    Without scratching them off to get the numbers and redeeming them there is no way for you to do so. You could go back to CVS and see if they can get the data from their computer or see if your receipt helps.

  • Need to find out the account group given the accounting document number

    I am new to SAP. Please help.
    Need to find out the account group given the accounting document number?

    If you are asking about account assignment group then that can be seen in billing document -> Header -> Accounting Data.

  • Need to find out the queries which did not executed in 2014

    Hi All,
    I need to find out the queries which start from YY  and did not executed in 2014, earlier we used to find out by looking into the technical content cube 0TCT_C02 but now its giving dump as number of queries increases. I tried to find out using table RSZCOMPDIR but not able to trace it exactly. Please suggest some alternative solution to find out the queries which did not execute in 2014 so that we can delete it.
    Thanks,
    Asim.

    Hi,
    RSDDSTAT_OLAP : This is the table which contains query execution details
    CALDAY field in that table gives you query execution date
    OBJNAM gives the query name
    As you said RSZCOMPDIR gives list of all queries. doing a lookup between these tables will identify the queris which are not executed in particular period.
    -Sriram

  • Can We find out gl posted date of an invoice

    Hi All,
    we need to find out the gl post date. we have a field 'gl date' which will refer to the accounting date but we are looking for  accounting entries posted date in gl from an invoice. to be very particular we want the table and field name of gl posted date of an invoice.Appreciate any inputs
    Thank you

    Hi Yugesh,
    If you query the ap_invoice_distributions_all table, you will see an accounting_date field. That is the accounting date that was used when the accounting was transferred to GL.
    The same accounting_date should match the xla_ae_headers table.
    The xla_ae_lines_all table has a gl_sl_link_id column which links to the gl_je_lines table.
    Cheryl

  • TS1646 We have several apple devices in our family who use my debit card for itune charges.  I need to find out which device (itune account) these charges are coming from.  Can you help?

    We have several apple devices in our family who use my debit card for itune charges.  I need to find out which device (itune account) these charges are coming from. Can you help?

    You can't tell which device a purhcase was made on, but if your family members each have their own iTunes account to which your card is linked then you can check the purchase history on each of those accounts via the Store > View Account menu option on your computer's iTunes - that should have 'purchase history' section with a 'see all' link to the right of it

  • How do i find out the tables (data)effected in a schema after a particular time stamp

    how do i find out the tables (data not structure)effected in a schema after a particular time stamp?
    pls email in [email protected]

    You can't do that. That would be a real security risc.
    /KAj

  • I no longer have access to system folders that allow me to remove old or incorrect PAGES templates. Need to find out how to do that. The only way I can do it now is to blank the template and replace the bad template with a blank.

    I no longer have access to system folders that allow me to remove old or incorrect PAGES templates. Need to find out how to do that. The only way I can do it now is to blank the template and replace the unwanted template with a blank. It was previously possible to go to MY TEMPLATES and remove the unwanted templates. I don't if this issue is before or since installation of 10.8 (a nightmare in my case, which led to significant failure issues).  And because I haven't tried to remove templates since finally managing to install 10.8 (now at 10.8.4), I don't know if this is typical of the newer OS or a problem. I've been a Mac user for more than 25 years, but I think I'm nearing the end of the road. By the way, I've never needed to do this before because the manuals always offered an answer... they don't seem to do that anymore. In any case, I don't know how this works... I'd prefer an email reply if that's possible. But that would probably be too easy, and I don't know how to get a reply.

    Thanks, I appreciate the help.  I think this is one of the problems Apple is creating by changing the OS so often. I had fomer colleagues at [a major aerospace contractor] who told me that so many original files were ultimately lost because of the deadly change in the "Save As" operation that they are now afraid of every OS update. Apple has badly damaged their support base with that very prominent company (they won't update now until they've fully examined and understand changes in the pre-conditioned nature of OS computer functions), and they are a whole lot less enthaled with Mac-related equipment/software. Can't blame them, I too used orginal files that way (as easy-to-use templates), and lost some important files before I realized what was happening (to late to revert). Companies should not have to retrain employees each time an OS gets an update, it's can be very expensive several different ways. They learned a painful lesson with that one. And because I'm now retired and don't use multiple devices, I need iCloud like I need a hole in the head... but I'm told there's no way to keep Apple out of my computer. Fortunately, because of major problems when initially installing Mountain Lion, one hold-over of the hardware/software damage I experienced was that iCloud can no longer access my computer even though everything else is working fine again. That was the only "good luck" I had as a result of that expensive nightmare.

Maybe you are looking for