Comparing data in two data sets in Oracle BI 11g

Hello,
I'm trying to compare the PO status of two systems and display the ones that donot have the same status. I'm able to join the data-sets with the link but unable to compare them. Can you please tell me?

Are you referring to BI Publisher 11g links !! Shed some light on your issue.
-bifacts

Similar Messages

  • How to get the data between two dates?

    Hi all,
    I am facing a problem of getting the data betwwen two dates.
    I have written a query as
    "select * from table1 a where a.dt between trunc(sysdate) and trunc(sysdate)-30"
    It is not showing any errors or warnings.But the data is not coming though the data is in the table1 between these two dates.
    Regards,
    Kumar

    Your ordering is probably wrong:
    SELECT *
      FROM table1 a
    WHERE a.dt BETWEEN TRUNC (SYSDATE) - 30 AND TRUNC (SYSDATE)

  • Findig dates between two dates

    Hi everybody,
    I have one table (TEST) with 2 columns having only one record
    i need list of dates between from_date and to_date
    the sample data...
    from_date to_date
    ====== ======
    02-JUL-09 17-JUL-2009
    I found below query to retrieve the dates between two dates.
    select to_date('02-jul-2009','dd-mon-yyyy')+level-1 dt from dual
    connect by level<=to_date('17-jul-2009','dd-mon-yyyy')-to_date('02-jul-2009','dd-mon-yyyy')+1
    It is working properly.
    i have changed the above query with my table column names
    select to_date(from_date,'dd-mon-yyyy')+level-1 dt from Test
    connect by level<=to_date(to_date,'dd-mon-yyyy')-to_date(from_date,'dd-mon-yyyy')+1
    In this case it is not working...
    i am unable to find the reason...
    Thank you.

    Hi,
    It is working fine for me, what is the data type for from_date and to_date.
    select to_date(from_date,'dd-mon-yyyy')+level-1 dt from Test
    connect by level<=to_date(to_date,'dd-mon-yyyy')-to_date(from_date,'dd-mon-yyyy')+1;
    DT
    02-JUL-09
    03-JUL-09
    04-JUL-09
    05-JUL-09
    06-JUL-09
    07-JUL-09
    08-JUL-09
    09-JUL-09
    10-JUL-09
    11-JUL-09
    12-JUL-09
    13-JUL-09
    14-JUL-09
    15-JUL-09
    16-JUL-09
    17-JUL-09Regards
    Anurag Tibrewal
    PS: Also post your output with the second query.

  • How to compare data in two data sources ?

    Hi,
    Avalaibilty : Two data Souces 1) Based on standard data available from External agencies ( FLAT FILE )
                                                      2) Generic Data Source having Source system as R3 Server.
    Requirement : To write a transfer routine such that each data transaction in the data field of R3 servers compares itself to the the respective data available in the external data source and updates the Infoprovider ( DSO ) accordingly .
    Exact problem : I want to check the no. of employees in my company that are using travel funds more than the iNdustry standard for the respective position and also if they are spending more than Industry standard altogether ( OR  Conditioon ) .
    What would be the structure of the Routines ? and how to comparre
    Mrinal

    Hi,
    Below logic can be used:
    Load the flat file data in DSO2. Then compare and insert the matching value a temp table TABLE1.
    SELECT <KF1>
               FROM <DSO1> INTO TABLE <TABLE1>
               WHERE <KF1> = <DSO2>/<KF2>;
    Then insert the contents of the temp table into the required CUBE/DSO.

  • Dates between two dates

    HI everyone!
    I'm trying to obtain the dates between two given dates....
    example:
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date a = sdf.parse("12/10/2005");
    Date b = sdf.parse("22/12/2005");My desired result its a ArrayList of all dates between that period...
    I already used the GregorianCalendar adding one day in a while condition until its equals the second date but it dosn't work for large periods of time...
    Can somebody help me with this task?
    thanks in advance !

    while(gc.getTime().compareTo(finaldate ) != 0){No, that's still fragile. You're still comparing EXACT values, instead of checking for when one equals OR EXCEEDS the other.
    If you're not going to use DrLaszlo's example to use the Calendar class for a better way, then at least do this instead:
    while(gc.getTime().compareTo(finaldate ) < 0){                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Occurrence of a date between two dates

    I want to find occurence of a particular date between two given dates.
    for example if I have 01/03/2006 and 01/01/2007 and I want to find
    if an 06th April exist between them, how do i find it?Pls help.. it's very urgent.
    Thnx
    RK

    Pls help.. it's very urgent.I hate this. If you started your homework a couple days before it was due, you wouldn't have this problem
    Anyway see
    Date.getTime()
    and
    Calendar.getTimeInMillis()
    If you've only got a String date, see SimpleDateFormat
    Once you have them all in long values, just compare the numbers to make sure the new date is > one of them and < the other

  • To filter data in two dates using combo box component

    Hi,
    I have a requirement like, i need to filter data in chart between two dates from two combo box.. From combo_box and To combo_box.
    I am using one QaaWS to populate LOV's into Combo box's and another QaaWS for chart data. Universe is the same one on SAP  BI query.
    LOV's are populating into both combo's and chart as well, i used a query refresh button after choosing two dates and press button.
    Data is not reflecting as per the choice of dates.
    If any one have such scenario, request you to share the same....
    Thanks in advance...
    Raj..

    Problem is with ranges, not with dates, my data is working fine with CALDAY (in BI Query)....
    My query variable is on FiscalPeriod month, like "FEB 2011"  to "OCT 2011" and is optional, but it is fails in QaaWS to execute when i try to input any months.
    If we give default values in BI query format is like K4/010.2011 for october month. QaaWS doesnt fail and executes, but if i change any value in QaaWS it is taking as "OCT 2011"
    And in Xcelsius it is not recognizing eaither of the formats like, K4/010.2011 or "OCT 2011"
    the format is not matching with xcelsius.

  • Data from two data providers

    In a report i want to fetch teh data from 2 data Providers. which condetion wil satisfy to link the 2 data providers.
    ex: Q1 have columns A,B,C
    Q2 has a X,Y,Z columns.
    requirement is like i want to get all the columns from those 2 tables in report level..like A,B,C,X,Y,Z in a single report.
    Regards
    Sunil

    Hi,
    As venu and karthik said you must a have a atleast one common dimension (same date type for both dimensions) two link two data providers to get a single report.
    For ur requirement check whether any one dimesions exists in both data providers. If so then goto Data Manager -> expand 1st DP ->select the common dimension -> right pane (at bottom) you will get link to button -> click and select the common dimension in 2nd DP.
    Repeat the above process for all the common dimensions and then drag and drop all the required objects to create a single report.
    Cheers,
    Suresh ALuri.

  • How to get the dates between Two dates excluding Saturaday and Sunday

    Dear All,
    select to_date('25-04-2012', 'DD-MM-YYYY') + rownum -1 dt
        from dual
        connect by level <= to_date('05-05-2012', 'DD-MM-YYYY') - to_date('25-04-2012', 'DD-MM-YYYY') + 1;The above query returning the following output,
    DT
    DT
    04/25/2012
    04/26/2012
    04/27/2012
    04/28/2012
    04/29/2012
    04/30/2012
    05/01/2012
    05/02/2012
    05/03/2012
    05/04/2012
    05/05/2012here I need to exclude the Dates which comes on 'saturday' and 'sunday' and also the common holiday
    Here it is '01-May-2012' and I need the output like the following,
    04/25/2012
    04/26/2012
    04/27/2012
    04/30/2012
    05/02/2012
    05/03/2012
    05/04/2012I need the common query to calculate between any two dates.
    Can anyone suggest me?
    Thank you,
    Regsrds,
    gurujothi

    Hi Frank,
    Sorry for my fault,
    The following is my table description,
    CREATE TABLE  "DATES"
       (     "FROMDATE" DATE,
         "TODATE" DATE,
                       "LEAVE_ID" Number(5)
    Insert into dates values('05-02-2012','05-05-2012',1);
    Create table holiday_dates(holidays date);
    insert into holiday_dates values('01-05-2012');Now when I used this query,
    select count(*) from (select dt
    from(
        select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
            from dates
            connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
    where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;
    Count(*)
       64
    Insert into dates values('01/05/2012','05/05/2012',2);
    /Now my table has 2 rows,
    select  *  from dates;
    FROMDATE     TODATE         LEAVE_ID
    01/05/2012     05/05/2012            1
    05/02/2012     05/05/2012            2Now when I used this query,
    select count(*) from (select dt
    from(
        select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
            from dates
            connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
    where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;The output is ,
    COUNT(*)
    1987How to get the output using the max(leave_id) like the following,
    select..........from... where leave_id=(select max(leave_id) from dates);where to add "WHERE" clause in the above query?
    Thank you,
    Regards,
    Gurujothi.
    Edited by: Gurujothi on May 3, 2012 8:43 PM
    Edited by: Gurujothi on May 3, 2012 8:44 PM

  • Sql Query for getting data between two dates

    Dear Sir,
    I have one problem, i have date stored in varchar datatype of (X) table in mysql as it was not supporting the date format of (dd/mm/yyyy) so know the problem is,
    When i going to get the data between the the two dates it is giving the un reliable answers such that
    when i am asking the query as data between 1st April to 31st December 2009 it is showing the data from the 2008 .
    is there any way to solve this problem,please help this is an urgent requirement, your replay will be helpful to me.
    With Regards
    Ramakrishna Y

    You either have a SQL problem and this is the incorrect place to ask.
    Or you have a Java problem in code we cannot see. When posting code use the code tags. Click the CODE button and paste your code between the tags that appear.

  • How to get list of all the dates between two dates

    Hi, Can anybody please help me ..
    I have two dates in string format ("dd/MM/yyyy).I need to get all the dates in between these two dates.How can I do thin in java
    Thanks in advance

    Look at classes Calendar and SimpleDateFormat.
    And get your abstraction straight: you don't have two dates. You have two Strings that represent a date. To use them, you have to convert them to Date objects first with SDF.

  • Generate linear dates betwen two dates

    Hi,
    There are two dates as input. need to generate series of dates between those dates. Dates must appear in column wise
    please suggest how to write the query on that.
    Eg: If we enter two dates as start date 1-JAN-2011 and end date as 5-JAN-2010
    It must generate a linear date as 1-JAN-2011 2-JAN-2011 3-JAN-2011 4-JAN-2011 5-JAN-2011
    date must appear as column wise. P|lease let me know
    Thanks
    Sudhir

    SQL> -- generating sample data:
    SQL> with t as (
      2  select to_date('1-JAN-2011', 'dd-mon-yyyy') start_date
      3  ,      to_date('5-JAN-2011', 'dd-mon-yyyy') end_date
      4  from   dual
      5  )
      6  --
      7  -- actual query:
      8  --
      9  select max(decode(max(lvl), 1, dt)) dt1
    10  ,      max(decode(max(lvl), 2, dt)) dt2
    11  ,      max(decode(max(lvl), 3, dt)) dt3
    12  ,      max(decode(max(lvl), 4, dt)) dt4
    13  ,      max(decode(max(lvl), 5, dt)) dt5
    14  from ( select start_date+level-1 dt
    15         ,      level lvl
    16         from   t
    17         connect by level <= end_date-start_date+1
    18       )
    19  group by dt;
    DT1                 DT2                 DT3                 DT4                 DT5
    01-01-2011 00:00:00 02-01-2011 00:00:00 03-01-2011 00:00:00 04-01-2011 00:00:00 05-01-2011 00:00:00
    1 row selected.
    SQL> -- generating sample data:
    SQL> with t as (
      2  select to_date('1-JAN-2011', 'dd-mon-yyyy') start_date
      3  ,      to_date('5-JAN-2011', 'dd-mon-yyyy') end_date
      4  from   dual
      5  )
      6  --
      7  -- actual query:
      8  --
      9  select max(decode(max(lvl), 1, dt)) dt1
    10  ,      max(decode(max(lvl), 2, dt)) dt2
    11  ,      max(decode(max(lvl), 3, dt)) dt3
    12  ,      max(decode(max(lvl), 4, dt)) dt4
    13  ,      max(decode(max(lvl), 5, dt)) dt5
    14  from ( select start_date+level-1 dt
    15         ,      level lvl
    16         from   t
    17         connect by level <= end_date-start_date+1
    18       )
    19  where to_char(dt, 'dy', 'nls_date_language=american') not in ('sat', 'sun')
    20  group by dt;
    DT1                 DT2                 DT3                 DT4                 DT5
                                            03-01-2011 00:00:00 04-01-2011 00:00:00 05-01-2011 00:00:00
    1 row selected.

  • SQL query to get dates between two dates

    Hi,
    We have one table with start date and end date...Now i need to get all dates between start date and end date...
    Table looks like below..
    Create table date_table (start_date date,end_date date);
    Data in the table will be like below:
    start_date            end_date
    01-Jan-2013       04-Jan-2013
    01-Feb-2013       03-Feb-2013
    01-May-2013        03-May-2013
    I want a result as below..
    holiday_dates
    01-Jan-2013
    02-Jan-2013
    03-Jan-2013
    04-Jan-2013
    01-Feb-2013
    02-Feb-2013
    03-Feb-2013
    01-May-2013
    02-May-2013
    03-May-2013
    Can any one helps..?

    select * from date_table;
    START_DAT END_DATE
    01-JAN-13 04-JAN-13
    01-FEB-13 07-FEB-13
    07-MAR-13 12-MAR-13
    select start_date-1+level output from
    date_table connect by level<=end_date-start_date+1
    and prior start_date=start_date and prior sys_guid() is not null
    OUTPUT
    01-JAN-13
    02-JAN-13
    03-JAN-13
    04-JAN-13
    01-FEB-13
    02-FEB-13
    03-FEB-13
    04-FEB-13
    05-FEB-13
    06-FEB-13
    07-FEB-13
    07-MAR-13
    08-MAR-13
    09-MAR-13
    10-MAR-13
    11-MAR-13
    12-MAR-13

  • Setting up Oracle DB 11G in a development environment

    Hi
    I need to setup a new development environment with Oracle Database 11g and Oracle Apps Server 10G Forms and Reports.
    Currently we are running a live system (using Microsoft Virtual PC) on a domain and the virtual servers are joined to the domain.
    Where I want to get to with the new development environment is to be able to eventually move these new virtual servers to a completely new domain.
    What would be the best way to set this up to minimize the amount of work when setting up the database and apps server with the assumption that I will want to migrate the virtual servers to a new domain in the future. Would it be better to set up a basic workgroup and do the installation of both virtual servers in a workgroup environment?
    Also besides having security enhancements is there any advantage of having Oracle installed on a server versus installing on a Windows XP box?
    Many thanks.
    Spencer

    İf you first try to create db you get above errors, then you select "Create new objects in schema" option drop&create process starts.
    Result :
    TESTTYPEıD_TRG, CUSTOMOPTıONıD_TRG , ıSSUEVERSİONTYPEıD_TRG triggers are dropped and but not created again. ETESTPAGEID_TRG, TESTCASEATTACHMENTID_TRG, ATTCHSTDATA_TRG are newly created instead
    As I mentioned above after creation of ATTCHSTDATA_TRG, it throws an error and process stop. In additon, due to this error, all the dropped views are not created again.
    All my problem is newly created triggers an couldnt created views I suppose.
    Please advice
    thank you

  • Data between two dates in a 12-month period

    Hello Gentlemen
    I am facing a problem hope you would solve it.
    I have a table
    CREATE TABLE MATCHES
    (MT_ID     NUMBER(4) CONSTRAINT MT_ID_PK PRIMARY KEY,
    START_DATE     DATE,
    END_DATE     DATE,
    TEAM_A     NUMBER(2),
    TEAM_B     NUMBER(2),
    SERIES_ID     NUMBER(3))
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B,SERIES_ID) VALUES(1,'1 Apr 1993', '5 Apr 1993',1,2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B,SERIES_ID) VALUES(2,'21 Apr 1993', '25 Apr 1993',2,1,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B,SERIES_ID) VALUES(3,'30 Mar 1994', '3 Apr 1994',4,2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B,SERIES_ID) VALUES(4,'1 May 1994', '5 May 1994',8,1,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B,SERIES_ID) VALUES(5,'24 Nov 1994', '28 Nov 1994',5,7,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B,SERIES_ID) VALUES(6,'31 Mar 1999', '4 Apr 1999',3,6,1);
    select * from matches order by 1
    MT_ID     START_DATE     END_DATE     TEAM_A     TEAM_B     SERIES_ID
    1     01-APR-93     05-APR-93     1     2     1
    2     21-APR-93     25-APR-93     2     1     1
    3     30-MAR-94     03-APR-94     4     2     1
    4     01-MAY-94     05-MAY-94     8     1     1
    5     24-NOV-94     28-NOV-94     5     7     1
    6     31-MAR-99     04-APR-99     3     6     1Where
    MT_ID is Match ID which is primary key
    stat_date is the start date of the match and end_date is the date on which the match ended.
    Each match has two teams i.e Team A and Team B. Each team has its unique ID. So in the above data there are eight teams form
    ID 1 to 8.
    Duration of match can be taken out if we minus the start date from the end date. For example:
    Select END_DATE-START_DATE +1
    From MATCHES
    END_DATE-START_DATE+1
    5
    5
    5
    5
    5
    5 1 is added to include the start day too.
    My requirment is as follows:
    For each of the 8 Teams, show
    1. How many matches they played in each of the 7 twelve month periods from 1 April 1993 to 31 March 2000? If a match overlaped a 12 month period, then it would be treated as one match each on either side on the 12 month period.
    For example, if a match started on 30 March 1994 and ended on 3 Apr 1994 then for the 12-month year starting from 1 Apr 1993 to 31 March 1994 it would be treated as one match and for the 12-month period starting from 1 Apr 1994 to 31 March 1995 it would be treated as another match. Becuase the match was split into 2 + 3 days on either side of the 12-month period.
    2. How many days each team was playing a match in each of the 7 twelve month periods from 1 April 1993 to 31 March 2000?
    For example, a team played 3 matches between Apr 1, 1993 and Mar 31, 1994. The Duration of each of the matches was 5+5+5 = 15 days. But the third match overlaped the 12-month period which started on 30 Mar 1994 and ended on 3 Apr 1994. So the correct number of playing days for that team would be 5 + 5 + 2 = 12 days from Apr 1, 1993 and Mar 31, 1994.
    A want an efficient query that gets me both of the above answers
    My desired output is like this:
    For Team ID = 1      
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    2    10    
    1-Apr-1994 to 31-Mar-1995    1    5
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    0    0
    1-Apr-1999 to 31-Mar-2000    0    0
    For Team ID = 2      
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    3    12    
    1-Apr-1994 to 31-Mar-1995    1    3
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    0    0
    1-Apr-1999 to 31-Mar-2000    0    0
    For Team ID = 3      
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    0    0    
    1-Apr-1994 to 31-Mar-1995    0    0
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    1    1
    1-Apr-1999 to 31-Mar-2000    1    4
    For Team ID = 4      
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    1    2    
    1-Apr-1994 to 31-Mar-1995    1    3
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    0    0
    1-Apr-1999 to 31-Mar-2000    0    0
    For Team ID = 5     
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    0    0    
    1-Apr-1994 to 31-Mar-1995    1    5
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    0    0
    1-Apr-1999 to 31-Mar-2000    0    0
    For Team ID = 6     
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    0    0    
    1-Apr-1994 to 31-Mar-1995    0    0
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    1    1
    1-Apr-1999 to 31-Mar-2000    1    4
    For Team ID = 7     
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    0    0    
    1-Apr-1994 to 31-Mar-1995    1    5
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    0    0
    1-Apr-1999 to 31-Mar-2000    0    0
    For Team ID = 8     
    Period                       MT   Playing Days
    1-Apr-1993 to 31-Mar-1994    0    0    
    1-Apr-1994 to 31-Mar-1995    1    5
    1-Apr-1995 to 31-Mar-1996    0    0
    1-Apr-1996 to 31-Mar-1997    0    0 
    1-Apr-1997 to 31-Mar-1998    0    0
    1-Apr-1998 to 31-Mar-1999    0    0
    1-Apr-1999 to 31-Mar-2000    0    0I would appreciate a prompt reply in this regard.
    Thanks in advance
    Ramis Shah

    Dear Oscar
    Thanks for your feedback. Yes, this problem has to be resolved becuase SQL from browser is better to work with. The command prompt SQLPlus is not user friendly.
    Any way, Oscar I checked your last query on the sample data that I also posted in my question. It was fine. But when I ran the query on my actual base table it did not gave me the correct results for frequency of six weeks gap. It showed 0 for even those gaps where there is actually a six week gap and where there was a gap of atleast six weeks on more than one ocassion in a 12-month period it shows only 1 for those.
    THe "Free days" were however generated correct by the query and its further accumulution to next period at cut-off point (31-Mar-YYYY) is also correct..But I missed to tell you one thing which I explained below.
    The is no difference in between the base tables and the dummy table. The only difference is ofcourse the data and the number of records.
    For this reason I copied here actual base table DDL data (54 records) in order to solve the
    problem.
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1615,'03-OCT-2002','07-OCT-2002',1,7);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1617,'11-OCT-2002','15-OCT-2002',7,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1620,'19-OCT-2002','23-OCT-2002',1,7);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1623,'07-NOV-2002','11-NOV-2002',1,2);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1628,'21-NOV-2002','25-NOV-2002',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1629,'29-NOV-2002','03-DEC-2002',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1634,'26-DEC-2002','30-DEC-2002',1,2);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1636,'02-JAN-2003','06-JAN-2003',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1638,'10-APR-2003','14-APR-2003',4,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1639,'19-APR-2003','23-APR-2003',1,4);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1643,'01-MAY-2003','05-MAY-2003',1,4);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1650,'18-JUL-2003','22-JUL-2003',12,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1652,'25-JUL-2003','29-JUL-2003',12,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1661,'09-OCT-2003','13-OCT-2003',1,11);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1663,'17-OCT-2003','21-OCT-2003',11,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1671,'04-DEC-2003','08-DEC-2003',1,6);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1673,'12-DEC-2003','16-DEC-2003',1,6 );
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1678,'26-DEC-2003','30-DEC-2003',6,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1680,'02-JAN-2004','06-JAN-2004',6,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1685,'08-MAR-2004','12-MAR-2004',1,9);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1688,'16-MAR-2004','20-MAR-2004',1,9);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1691,'24-MAR-2004','28-MAR-2004',1,9);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1706,'09-JUL-2004','13-JUL-2004',1,9);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1720,'03-NOV-2004','07-NOV-2004',6,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1721,'18-NOV-2004','22-NOV-2004',5,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1723,'26-NOV-2004','30-NOV-2004',1,5);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1726,'16-DEC-2004','20-DEC-2004',1,7);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1729,'26-DEC-2004','30-DEC-2004',7,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1731,'02-JAN-2005','06-JAN-2005',7,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1739,'10-MAR-2005','14-MAR-2005',5,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1742,'18-MAR-2005','22-MAR-2005',1,5);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1744,'26-MAR-2005','30-MAR-2005',5,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1756,'21-JUL-2005','25-JUL-2005',1,2);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1758,'04-AUG-2005','08-AUG-2005',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1760,'11-AUG-2005','15-AUG-2005',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1762,'25-AUG-2005','29-AUG-2005',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1763,'08-SEP-2005','12-SEP-2005',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1768,'14-OCT-2005','19-OCT-2005',1,21);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1769,'03-NOV-2005','07-NOV-2005',1,4);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1771,'17-NOV-2005','21-NOV-2005',4,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1773,'25-NOV-2005','29-NOV-2005',4,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1777,'16-DEC-2005','20-DEC-2005',1,3);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1779,'26-DEC-2005','30-DEC-2005',1,3);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1780,'02-JAN-2006','06-JAN-2006',3,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1789,'16-MAR-2006','20-MAR-2006',3,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1792,'24-MAR-2006','28-MAR-2006',1,3);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1795,'31-MAR-2006','04-APR-2006',3,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1797,'09-APR-2006','13-APR-2006',12,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1799,'16-APR-2006','20-APR-2006',12,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1817,'23-NOV-2006','27-NOV-2006',1,2);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1819,'01-DEC-2006','05-DEC-2006',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1821,'14-DEC-2006','18-DEC-2006',1,2);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1824,'26-DEC-2006','30-DEC-2006',2,1);
    INSERT INTO MATCHES (MT_ID,START_DATE,END_DATE,TEAM_A,TEAM_B) VALUES (1826,'02-JAN-2007','06-JAN-2007',2,1);Select * from matches
    MT_ID    START_DATE      END_DATE   TEAM_A  TEAM_B    
    1615     03-OCT-2002     07-OCT-2002     1     7    
    1617     11-OCT-2002     15-OCT-2002     7     1    
    1620     19-OCT-2002     23-OCT-2002     1     7    
    1623     07-NOV-2002     11-NOV-2002     1     2    
    1628     21-NOV-2002     25-NOV-2002     2     1    
    1629     29-NOV-2002     03-DEC-2002     2     1    
    1634     26-DEC-2002     30-DEC-2002     1     2    
    1636     02-JAN-2003     06-JAN-2003     2     1    
    1638     10-APR-2003     14-APR-2003     4     1    
    1639     19-APR-2003     23-APR-2003     1     4    
    1643     01-MAY-2003     05-MAY-2003     1     4    
    1650     18-JUL-2003     22-JUL-2003     12    1    
    1652     25-JUL-2003     29-JUL-2003     12    1    
    1661     09-OCT-2003     13-OCT-2003     1     11    
    1663     17-OCT-2003     21-OCT-2003     11    1    
    1671     04-DEC-2003     08-DEC-2003     1     6    
    1673     12-DEC-2003     16-DEC-2003     1     6    
    1678     26-DEC-2003     30-DEC-2003     6     1    
    1680     02-JAN-2004     06-JAN-2004     6     1    
    1685     08-MAR-2004     12-MAR-2004     1     9    
    1688     16-MAR-2004     20-MAR-2004     1     9    
    1691     24-MAR-2004     28-MAR-2004     1     9    
    1706     09-JUL-2004     13-JUL-2004     1     9    
    1720     03-NOV-2004     07-NOV-2004     6     1    
    1721     18-NOV-2004     22-NOV-2004     5     1    
    1723     26-NOV-2004     30-NOV-2004     1     5    
    1726     16-DEC-2004     20-DEC-2004     1     7    
    1729     26-DEC-2004     30-DEC-2004     7     1    
    1731     02-JAN-2005     06-JAN-2005     7     1    
    1739     10-MAR-2005     14-MAR-2005     5     1    
    1742     18-MAR-2005     22-MAR-2005     1     5    
    1744     26-MAR-2005     30-MAR-2005     5     1    
    1756     21-JUL-2005     25-JUL-2005     1     2    
    1758     04-AUG-2005     08-AUG-2005     2     1    
    1760     11-AUG-2005     15-AUG-2005     2     1    
    1762     25-AUG-2005     29-AUG-2005     2     1    
    1763     08-SEP-2005     12-SEP-2005     2     1    
    1768     14-OCT-2005     19-OCT-2005     1     21    
    1769     03-NOV-2005     07-NOV-2005     1     4    
    1771     17-NOV-2005     21-NOV-2005     4     1    
    1773     25-NOV-2005     29-NOV-2005     4     1    
    1777     16-DEC-2005     20-DEC-2005     1     3    
    1779     26-DEC-2005     30-DEC-2005     1     3    
    1780     02-JAN-2006     06-JAN-2006     3     1    
    1789     16-MAR-2006     20-MAR-2006     3     1    
    1792     24-MAR-2006     28-MAR-2006     1     3    
    1795     31-MAR-2006     04-APR-2006     3     1    
    1797     09-APR-2006     13-APR-2006     12    1    
    1799     16-APR-2006     20-APR-2006     12    1    
    1817     23-NOV-2006     27-NOV-2006     1     2    
    1819     01-DEC-2006     05-DEC-2006     2     1    
    1821     14-DEC-2006     18-DEC-2006     1     2    
    1824     26-DEC-2006     30-DEC-2006     2     1    
    1826     02-JAN-2007     06-JAN-2007     2     1     Now, I run my query to show the number of free days between each Test for matches played by TEAM = 1
    SELECT MT_ID, START_OF_FREE_DAYS,
    START_DATE-1 END_OF_FREE_DAYS, START_DATE, END_DATE, TEAM_A,
    TEAM_B, FREE_DAYS, to_char( trunc(FREE_DAYS/7)+mod(FREE_DAYS,7)/10,'990.0') WEEKS1
    FROM
    select MT_ID, lag(END_DATE, 1) over (order by MT_ID)+1 START_OF_FREE_DAYS,
    START_DATE,
    END_DATE,
    TEAM_A, TEAM_B,
    CASE
       WHEN DECODE(START_DATE-lag(START_DATE, 1) over (order by    
    MT_ID)-1,-1,0,START_DATE-lag(START_DATE, 1) over (order by MT_ID)-1) <= 4 THEN 0
       WHEN DECODE(START_DATE-lag(START_DATE, 1) over (order by    
    MT_ID)-1,-1,0,START_DATE-lag(START_DATE, 1) over (order by MT_ID)-1) > 4 THEN    
    START_DATE-lag(END_DATE, 1) over (order by MT_ID)-1 END FREE_DAYS
    FROM
    MATCHES where TEAM_A = 1 OR TEAM_B = 1
    MT_ID   START_OF   END_OF_   START_DATE  END_DATE  TEAM_ TEAM FREE_ Weeks1
                                 FREEDAYS FREE_DAYS    A    _B DAYS 
    1615   -           02-OCT-02   03-OCT-02   07-OCT-02   1   7   -     -     
    1617   08-OCT-02   10-OCT-02   11-OCT-02   15-OCT-02   7   1   3   0.3  
    1620   16-OCT-02   18-OCT-02   19-OCT-02   23-OCT-02   1   7   3   0.3  
    1623   24-OCT-02   06-NOV-02   07-NOV-02   11-NOV-02   1   2   14  2.0  
    1628   12-NOV-02   20-NOV-02   21-NOV-02   25-NOV-02   2   1   9   1.2  
    1629   26-NOV-02   28-NOV-02   29-NOV-02   03-DEC-02   2   1   3   0.3  
    1634   04-DEC-02   25-DEC-02   26-DEC-02   30-DEC-02   1   2   22  3.1  
    1636   31-DEC-02   01-JAN-03   02-JAN-03   06-JAN-03   2   1   2   0.2  
    1638   07-JAN-03   09-APR-03   10-APR-03   14-APR-03   4   1   93  13.2  
    1639   15-APR-03   18-APR-03   19-APR-03   23-APR-03   1   4   4   0.4  
    1643   24-APR-03   30-APR-03   01-MAY-03   05-MAY-03   1   4   7   1.0  
    1650   06-MAY-03   17-JUL-03   18-JUL-03   22-JUL-03   12  1   73  10.3  
    1652   23-JUL-03   24-JUL-03   25-JUL-03   29-JUL-03   12  1   2   0.2  
    1661   30-JUL-03   08-OCT-03   09-OCT-03   13-OCT-03   1   11  71  10.1  
    1663   14-OCT-03   16-OCT-03   17-OCT-03   21-OCT-03   11  1   3   0.3  
    1671   22-OCT-03   03-DEC-03   04-DEC-03   08-DEC-03   1   6   43  6.1  
    1673   09-DEC-03   11-DEC-03   12-DEC-03   16-DEC-03   1   6   3   0.3  
    1678   17-DEC-03   25-DEC-03   26-DEC-03   30-DEC-03   6   1   9   1.2  
    1680   31-DEC-03   01-JAN-04   02-JAN-04   06-JAN-04   6   1   2   0.2  
    1685   07-JAN-04   07-MAR-04   08-MAR-04   12-MAR-04   1   9   61  8.5  
    1688   13-MAR-04   15-MAR-04   16-MAR-04   20-MAR-04   1   9   3   0.3  
    1691   21-MAR-04   23-MAR-04   24-MAR-04   28-MAR-04   1   9   3   0.3  
    1706   29-MAR-04   08-JUL-04   09-JUL-04   13-JUL-04   1   9   102 14.4  
    1720   14-JUL-04   02-NOV-04   03-NOV-04   07-NOV-04   6   1   112 16.0  
    1721   08-NOV-04   17-NOV-04   18-NOV-04   22-NOV-04   5   1   10  1.3  
    1723   23-NOV-04   25-NOV-04   26-NOV-04   30-NOV-04   1   5   3   0.3  
    1726   01-DEC-04   15-DEC-04   16-DEC-04   20-DEC-04   1   7   15  2.1  
    1729   21-DEC-04   25-DEC-04   26-DEC-04   30-DEC-04   7   1   5   0.5  
    1731   31-DEC-04   01-JAN-05   02-JAN-05   06-JAN-05   7   1   2   0.2  
    1739   07-JAN-05   09-MAR-05   10-MAR-05   14-MAR-05   5   1   62  8.6  
    1742   15-MAR-05   17-MAR-05   18-MAR-05   22-MAR-05   1   5   3   0.3  
    1744   23-MAR-05   25-MAR-05   26-MAR-05   30-MAR-05   5   1   3   0.3  
    1756   31-MAR-05   20-JUL-05   21-JUL-05   25-JUL-05   1   2   112 16.0  
    1758   26-JUL-05   03-AUG-05   04-AUG-05   08-AUG-05   2   1   9   1.2  
    1760   09-AUG-05   10-AUG-05   11-AUG-05   15-AUG-05   2   1   2   0.2  
    1762   16-AUG-05   24-AUG-05   25-AUG-05   29-AUG-05   2   1   9   1.2  
    1763   30-AUG-05   07-SEP-05   08-SEP-05   12-SEP-05   2   1   9   1.2  
    1768   13-SEP-05   13-OCT-05   14-OCT-05   19-OCT-05   1   21  31  4.3  
    1769   20-OCT-05   02-NOV-05   03-NOV-05   07-NOV-05   1   4   14  2.0  
    1771   08-NOV-05   16-NOV-05   17-NOV-05   21-NOV-05   4   1   9   1.2  
    1773   22-NOV-05   24-NOV-05   25-NOV-05   29-NOV-05   4   1   3   0.3  
    1777   30-NOV-05   15-DEC-05   16-DEC-05   20-DEC-05   1   3   16  2.2  
    1779   21-DEC-05   25-DEC-05   26-DEC-05   30-DEC-05   1   3   5   0.5  
    1780   31-DEC-05   01-JAN-06   02-JAN-06   06-JAN-06   3   1   2   0.2  
    1789   07-JAN-06   15-MAR-06   16-MAR-06   20-MAR-06   3   1   68  9.5  
    1792   21-MAR-06   23-MAR-06   24-MAR-06   28-MAR-06   1   3   3   0.3  
    1795   29-MAR-06   30-MAR-06   31-MAR-06   04-APR-06   3   1   2   0.2  
    1797   05-APR-06   08-APR-06   09-APR-06   13-APR-06   12  1   4   0.4  
    1799   14-APR-06   15-APR-06   16-APR-06   20-APR-06   12  1   2   0.2  
    1817   21-APR-06   22-NOV-06   23-NOV-06   27-NOV-06   1   2   216 30.6  
    1819   28-NOV-06   30-NOV-06   01-DEC-06   05-DEC-06   2   1   3   0.3  
    1821   06-DEC-06   13-DEC-06   14-DEC-06   18-DEC-06   1   2   8   1.1  
    1824   19-DEC-06   25-DEC-06   26-DEC-06   30-DEC-06   2   1   7   1.0  
    1826   31-DEC-06   01-JAN-07   02-JAN-07   06-JAN-07   2   1   2   0.2   As you see there is one 93-day gap (from 07-JAN-03 to 09-APR-03) before MT_ID = 1638 of which 84 days come between period 01-Apr-2002 to 31-Mar-2003 and the remaining nine from April 1 to 9. This one six-week gap is very well showed by the result of your query below. But in the period from 01-Apr-2003 to 31-Mar-2004 your query below does not show any six-week gap. whereas in the same period, above the results show four instances of atleast 42-days gap. i.e. 73, 71, 43 and 61 days.
    So your query should show the following for this period:
    TOT   TEAM PERIOD                    FREEDAYS EXISTS_SIX_WEEK_GAP  
    -      1   01-Apr-2003 to 31-Mar-2004   296   4   Same is true for the next period 01-Apr-2004 to 31-Mar-2005.
    For other TEAM ID's the six-week results generated by your query are ok, becuase for each of those teams, except for Team = 21, there was only one instance of 42 days gap. The query fails only when there is more than one 42-days gap.
    For Team = 21, The query shows 1 instance of six-week gap but doesn't show the number of free days for that period. This is mainly becuase I told you in my question the other day that Free Days are calculated by taking the diffrence between the end date of the previous match and the start date of the current match. Since team = 21 played only one match so that's why the query showed no free-days becuase it did not found any previous date to take the difference. For this purpose I rephrase my question below the following table.
    When I run your query, modifying the start period to 1-Apr-2002 instead of 1992 and connect by
    level <= 5,
    with periods as ( select add_months(dt,12*(rownum-1)) start_period,
                             add_months(dt,12*rownum)-1 end_period
                      from (select to_date('1-Apr-2002') dt from dual)
                      connect by level <= 5),
    ....,on my actual data it gives me the following result:
    TOT   TEAM PERIOD                    FREEDAYS EXISTS_SIX_WEEK_GAP  
    -      1   01-Apr-2002 to 31-Mar-2003   140   1  
    -      1   01-Apr-2003 to 31-Mar-2004   296   0  
    -      1   01-Apr-2004 to 31-Mar-2005   315   0  
    -      1   01-Apr-2005 to 31-Mar-2006   293   0  
    -      1   01-Apr-2006 to 31-Mar-2007   242   0  
    TOTAL  1                         -      1286  1  
    -      2   01-Apr-2002 to 31-Mar-2003   120   1  
    -      2   01-Apr-2003 to 31-Mar-2004   366   0  
    -      2   01-Apr-2004 to 31-Mar-2005   365   0  
    -      2   01-Apr-2005 to 31-Mar-2006   340   0  
    -      2   01-Apr-2006 to 31-Mar-2007   256   0  
    TOTAL  2                         -      1447  1  
    -      3   01-Apr-2002 to 31-Mar-2003   0     0  
    -      3   01-Apr-2003 to 31-Mar-2004   0     0  
    -      3   01-Apr-2004 to 31-Mar-2005   0     0  
    -      3   01-Apr-2005 to 31-Mar-2006   80    1  
    -      3   01-Apr-2006 to 31-Mar-2007   0     0  
    TOTAL  3                         -      80    1  
    -      4   01-Apr-2002 to 31-Mar-2003   0     0  
    -      4   01-Apr-2003 to 31-Mar-2004   342   1  
    -      4   01-Apr-2004 to 31-Mar-2005   365   0  
    -      4   01-Apr-2005 to 31-Mar-2006   228   0  
    -      4   01-Apr-2006 to 31-Mar-2007   0     0  
    TOTAL  4                         -      935   1  
    -      5   01-Apr-2002 to 31-Mar-2003   0     0  
    -      5   01-Apr-2003 to 31-Mar-2004   0     0  
    -      5   01-Apr-2004 to 31-Mar-2005   108   1  
    -      5   01-Apr-2005 to 31-Mar-2006   0     0  
    -      5   01-Apr-2006 to 31-Mar-2007   0     0  
    TOTAL  5                         -      108   1  
    -      6   01-Apr-2002 to 31-Mar-2003   0     0  
    -      6   01-Apr-2003 to 31-Mar-2004   99    1  
    -      6   01-Apr-2004 to 31-Mar-2005   216   0  
    -      6   01-Apr-2005 to 31-Mar-2006   0     0  
    -      6   01-Apr-2006 to 31-Mar-2007   0     0  
    TOTAL  6                         -      315   1  
    -      7   01-Apr-2002 to 31-Mar-2003   165   1  
    -      7   01-Apr-2003 to 31-Mar-2004   366   0  
    -      7   01-Apr-2004 to 31-Mar-2005   266   0  
    -      7   01-Apr-2005 to 31-Mar-2006   0     0  
    -      7   01-Apr-2006 to 31-Mar-2007   0     0  
    TOTAL  7                         -      797   1  
    -      9   01-Apr-2002 to 31-Mar-2003   0     0  
    -      9   01-Apr-2003 to 31-Mar-2004   9     1  
    -      9   01-Apr-2004 to 31-Mar-2005   99    0  
    -      9   01-Apr-2005 to 31-Mar-2006   0     0  
    -      9   01-Apr-2006 to 31-Mar-2007   0     0  
    TOTAL  9                         -      108   1  
    -      11   01-Apr-2002 to 31-Mar-2003  0     0  
    -      11   01-Apr-2003 to 31-Mar-2004  3     1  
    -      11   01-Apr-2004 to 31-Mar-2005  0     0  
    -      11   01-Apr-2005 to 31-Mar-2006  0     0  
    -      11   01-Apr-2006 to 31-Mar-2007  0     0  
    TOTAL  11                        -      3     1  
    -      12   01-Apr-2002 to 31-Mar-2003  0     0  
    -      12   01-Apr-2003 to 31-Mar-2004  248   1  
    -      12   01-Apr-2004 to 31-Mar-2005  365   0  
    -      12   01-Apr-2005 to 31-Mar-2006  365   0  
    -      12   01-Apr-2006 to 31-Mar-2007  10    0  
    TOTAL  12                         -     988   1  
    -      21   01-Apr-2002 to 31-Mar-2003   0    0  
    -      21   01-Apr-2003 to 31-Mar-2004   0    0  
    -      21   01-Apr-2004 to 31-Mar-2005   0    0  
    -      21   01-Apr-2005 to 31-Mar-2006   0    1  
    -      21   01-Apr-2006 to 31-Mar-2007   0    0  
    TOTAL  21                         -      0    1   I want that Free-days should be calculated in the following way:
    1. The number of free-days for each team would be calculated by the taking the difference between the end-date of the previous match and the start date of the current match.
    2.If there is no previous match or the current match is the first match of the respective team in that 12-month period then the number of free-days would be calculated by taking the difference between the start date of that respective period (say 1-Apr-2002) and the start date of the current match. For example, Team = 21 played its first and only match in the 12-month period (01-Apr-2005 to 31-Mar-2006) from 14-19 OCT-,2005. So for this team the number of free days in this period would be 196 days (from 1-Apr-05 to 13-Oct-05) before this match and since no further match is played by this team in that period so the free days (163) from 20-Oct-2005 till 31-Mar-2006 (period end) would also come into this period. Hence the total number of free days by team = 21 in this period would be 196 + 163 = 359 days. The six-week gaps were two for this team in this period. Similary, for Team = 1 in the period from 1-April-2002 to 31-mar 2003, it played it first match from 03-07 OCT, 2002. Its free days for that period currently shown are 140 but
    they should be 325 (140 + 185 days ==> from 1 April 2002 to OCt 2, 2002).
    3. If a team plays its last match in any period well before end period say by Jan 6, 2007, then the period from Jan 7 to March 31, would also be counted in the free days. If the current date or SYSDATE is less then March 31, 2007, then the free-days would be counted from Jan 7 to current date or SYSdate.
    4. If a team played no match in any period then the total number of days in that period would come as free days and this would count as only 1 six-week gap in that period.
    5. If the free days overlaped a 12-month period then the number of free days that came till the end of the period break point would come into the preceding period and the remaining number of free days would come in the next 12-month period. For exmaple, a team played a match from 01-MAY-94 to 05-MAY-1994 and then played its next match on 01-APR-1999 to 05-APR-1999. So the number of free days between 06-MAY-1994 TO 31-MAR-1999 are 1791 days. (This condition is already well done by your current query). Lastly, for an overlaping gap (over 2 or more periods), the frequency of atleast six-weeks would only come in the period from where the six-week gap started.
    I would prefer results in the format below. The free-days gaps in each period are breaked-up into actual gaps, showing the start and end date of the gap and the number of days and the "1" if the gap is of atleast 42 days. the first line of each period shows the sum of the total number of playing days between that period, sum of free days for each period and the sum of six-weeks for that period.
    TOT   TEAM PERIOD                     Playing_days  FREEDAYS   EXISTS_SIX_WEEK_GAP  
    -      1   01-Apr-2002 to 31-Mar-2003    40             325        2
                  01-Apr-02 to 02-OCT-02                    185        1
                  08-OCT-02 to 10-OCT-02                      3        -
                  16-OCT-02 to 18-OCT-02                      3        -
                  24-OCT-02 to 06-NOV-02                     14        -
                  12-NOV-02 to 20-NOV-02                      9        -
                  26-NOV-02 to 28-NOV-02                      3        -
                  04-DEC-02 to 25-DEC-02                     22        -
                  31-DEC-02 to 01-JAN-03                      2        -
                  07-JAN-03 to 31-Mar-03                     84        1
              01-Apr-2003 to 31-Mar-2004     70             296        4
                  01-Apr-03 to 09-Apr-03                      9        -
                  15-APR-03 to 18-APR-03                      4        -    
                  24-APR-03 to 30-APR-03                      7        -    
                  06-MAY-03 to 17-JUL-03                     73        1    
                  23-JUL-03 to 24-JUL-03                      2        -    
                  30-JUL-03 to 08-OCT-03                     71        1    
                  14-OCT-03 to 16-OCT-03                      3        -    
                  22-OCT-03 to 03-DEC-03                     43        1    
                  09-DEC-03 to 11-DEC-03                      3        -    
                  17-DEC-03 to 25-DEC-03                      9        -    
                  31-DEC-03 to 01-JAN-04                      2        -    
                  07-JAN-04 to 07-MAR-04                     61        1    
                  13-MAR-04 to 15-MAR-04                      3        -    
                  21-MAR-04 to 23-MAR-04                      3        -    
                  29-MAR-04 to 31-Mar-04                      3        -
              01-Apr-2004 to 31-Mar-2005     
              01-Apr-2005 to 31-Mar-2006  
              01-Apr-2006 to 31-Mar-2007     
    Grand TOTAL                                       I hope everything would be clear this time too.
    Oscar, I am sorry for taking alot of your precious time. But I badly need to have this query in order to have the results for my huge data analysis.
    Kind regards
    Ramis

Maybe you are looking for

  • 8.1.5.-automate database shutdown:hepl needed

    I have tried to setup the automate database shutdown by following Oracle Manual. When rebooting the Unix system(sun solaris 2.6), nothing could be recorded in the alert logfile. After manually starting up the database, alert logfile indicated always

  • Importing packages under Mac OS X

    I'm trying to import a .jar package, but I keep getting run-time errors. The revelant lines of code: "import cs1.Keyboard; public class cubeEdge      public static void main (String[] args)           side = Keyboard.readInt();" cs1.jar is in the same

  • Oracle 11.1.0.6 RDBMS Upgrade to 11.2  What Patch Number for Linux?

    I have Oracle RDBMS 11.1.0.6 on 64bit Linux two node RAC and trying to find out what is the patch number to upgrade the database to R2. Thanks

  • Problem with OWB

    I have a problem during upgrade OWB 9.2.0.4, while create a new runtime repository... this is error log oracle.wh.util.DebugUtility: [validateRTChoicePage]: I am in RTChoicePage oracle.wh.util.DebugUtility: [validateRTChoicePage]: Check Oracle_Home f

  • Generic Data Source Enahncement

    Hi All, I have to add two field from a Z*table in source system into an existing Generic Data Source based on a functional module. What should be the approach ? Kind regards, Tapish