Help needed in generating the query

Hi All,
While fetching the required columns from the table, i also have to display the seq no starting with some no. ( which will vary based on the functionality, so it ll be a sep variable.) and will get incremented with a offset value.
Current code:
select col1, col2, col3 from table1 where col1 = valid_condition; Expected code / Or approach:
select start_val+offset_val , col1, col2, col3 from table1 where col1 = valid_condition; This select query is part of a view and the values for start_val, offset_val will be set as global params.
Is there any easier way of implementing this in the query, other than creating a seq no.
thanks in advance.

Hi,
This sounds like a job for ROWNUM or ROW_NUMBER.
The ROWNUM pseudo-column is easy to use, but the numbers aren't necessarily assigned in the order you'd like:
SELECT       ename
,       1000 + ROWNUM          AS seq_no
FROM       scott.emp
WHERE       deptno     = 30
ORDER BY  ename
;Output:
ENAME          SEQ_NO
ALLEN            1001
BLAKE            1004
JAMES            1006
MARTIN           1003
TURNER           1005
WARD             1002To assign the numbers in order, you could select ROWNUM from an ordered sub-query (or view), but if you're going to that much trouble, you might as well use the analytic ROW_NUMBER function:
SELECT       ename
,       1000 + ROW_NUMBER () OVER (ORDER BY ename)          AS seq_no
FROM       scott.emp
WHERE       deptno     = 30
ORDER BY  ename
;Output:
ENAME          SEQ_NO
ALLEN            1001
BLAKE            1002
JAMES            1003
MARTIN           1004
TURNER           1005
WARD             1006Edited by: Frank Kulash on Nov 25, 2009 1:32 PM

Similar Messages

  • Help needed to optimize the query

    Help needed to optimize the query:
    The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
    This is having high cost and taking around 15mins to execute.
    Can anyone help to fine-tune this??
       SELECT c.H_SEC,
                    c.S_PAID,
                    c.H_PAID,
                    table_c.EFF_DATE
       FROM    MTCH_TBL c
                    LEFT OUTER JOIN
                       (SELECT b.SEC_ALIAS,
                               b.EFF_DATE,
                               b.INSTANCE
                          FROM HIST_TBL b
                         WHERE b.EFF_DATE =
                                  (SELECT MAX (b2.EFF_DATE)
                                     FROM HIST_TBL b2
                                    WHERE b.SEC_ALIAS = b2.SEC_ALIAS
                                          AND b.INSTANCE =
                                                 b2.INSTANCE
                                          AND b2.EFF_DATE >= '01-Jan-2007')
                               OR b.EFF_DATE IS NULL) table_c
                    ON  table_c.SEC_ALIAS=c.H_SEC
                       AND table_c.INSTANCE = 100;

    To start with, I would avoid scanning HIST_TBL twice.
    Try this
    select c.h_sec
         , c.s_paid
         , c.h_paid
         , table_c.eff_date
      from mtch_tbl c
      left
      join (
              select sec_alias
                   , eff_date
                   , instance
                from (
                        select sec_alias
                             , eff_date
                             , instance
                             , max(eff_date) over(partition by sec_alias, instance) max_eff_date
                          from hist_tbl b
                         where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
                            or eff_date is null
               where eff_date = max_eff_date
                  or eff_date is null
           ) table_c
        on table_c.sec_alias = c.h_sec
       and table_c.instance  = 100;

  • Help needed to tune the Query:Statistics added

    Can someone DBA please help me to tune this query:
    SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
    CASE
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    ELSE
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
    FROM
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN ('%')
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
    AND NVL(G.OFFICE_ID,0) IN ('%')
    AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
    ORDER BY PROFILE_NM
    The number of rows in these tables are as follows:
    PROFILE_PORTAL -- 2392
    TBL_BDA_AGENCY_RESP_REP 3508
    TBL_BDA_AGENCY_OFFICE 2151
    TBL_BDA_OFFICE 3
    USERS_PORTAL 270500
    TBL_BDA_USR_ISS_GRP 234
    TBL_BDA_ISS_GROUP 2
    ATTRIBUTE_VALUES_PORTAL 2790
    PROFILE_TYPE_PORTAL 3
    The Explain pal nhas given this o/p to me:
    SQL> select * from table(dbms_xplan.display) dual;
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
    | 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
    | 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
    |* 2 | FILTER | | | | | |
    |* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
    |* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
    |* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
    | 6 | NESTED LOOPS | | 7 | 805 | | 37 |
    | 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
    |* 8 | FILTER | | | | | |
    | 9 | NESTED LOOPS OUTER | | | | | |
    |* 10 | FILTER | | | | | |
    | 11 | NESTED LOOPS OUTER | | | | | |
    | 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
    |* 13 | HASH JOIN | | 3 | 120 | | 7 |
    |* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
    |* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
    |* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
    | 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
    |* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
    | 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
    |* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    | 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
    |* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
    |* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
    | 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
    | 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
    |* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
    |* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    Predicate Information (identified by operation id):
    2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
    AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
    3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
    4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
    5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
    8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
    10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
    13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
    14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
    NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
    15 - filter("L"."APPLICATION_CD"='BDA')
    16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
    18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
    20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
    22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
    23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
    26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
    27 - access("T"."AGENCY_ID"=:B1)
    Note: cpu costing is off
    57 rows selected.
    Elapsed: 00:00:01.08
    Please help me.
    Aashish S.

    Hello Eric,
    Here is the code:
    SELECT DISTINCT
    K.ATTRIBUTE_VALUE AGENCY_ID,
    B.PROFILE_NM ,
    NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
    f.OFFICE_ID,
    B.PROFILE_ID,
    '%' ROLE,
    '%' LAYOUT,
    case
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    else
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','&lt;a sbcuid_in=' || H.USERID || ' target=NEW &gt;'||H.FIRSTNAME || ' ' || H.LASTNAME ||
    '( ' || H.USERID || ' )&lt;/a&gt;' ) USER_NAME
    from
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS
    (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN (1)
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0))
    LIKE '%'
    OR NVL(B.PROFILE_ID,0) IN (1))
    AND NVL(G.OFFICE_ID,0) IN (1)
    AND (to_char(NVL(C.RESP_USR_ID,'0'))
    LIKE '%'
    OR NVL(C.RESP_USR_ID,'0') IN ('%'))
    ORDER BY PROFILE_NM
    This is the Query and the query takes some mins. to run in prod environment.
    From the Query plan ,I am not able to get any idea for optimization.
    Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
    Thanks.
    Aashish S.

  • Help need to generate query

    Hi,
    I have the following info from a table named X.
    Col1 Col2 Col3 Col4
    IT01 20 01 X
    IT01 20 50 X
    IT01 30 01 X
    IT01 30 50 X
    If Col4 has value ‘X’ all the 4 combinations of Col2 & Col3, The result should be displayed as
    Col1 Col4
    IT01 X
    If the actual values are like
    Col1 Col2 Col3 Col4
    IT01 20 01 X
    IT01 20 50 X
    IT01 30 01 X
    IT01 30 50 Y
    Then The result should be displayed as
    Col1 Col4
    IT01 Y
    How will generate the query for this?
    Thanks,
    Titus Thomas
    Edited by: Titus Thomas on Apr 20, 2010 2:48 PM

    Try this:
    with test_tab as (select 'ITO1' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 30 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 30 Col2, 50 Col3, 'Y' Col4 from dual)
    --- end of mimicking your data; use SQL below:                 
    select col1, max(col4) col4
    from   test_tab
    group by col1;
    COL1 COL4
    ITO2 Y  
    ITO1 X  

  • Need to generate the excel file with diffrent sheets using utl_file package

    Hi,
    Sorry for previous message in which I had missed the usage of " UTL_FILE " package
    I need to generate the excel file with diffrent sheets . Currently I am generating the data in three diffrent excel files using
    " UTL_File " package and my requirement is to generate this in a single excel file with diffrent sheets.
    Please help on this
    Thanks & Regards,
    Krishna Vyavahare

    Hello 10866107,
    at Re: How to save a query result and export it to, say excell? you can find links to different solutions. At least the packages behind second and fourth link support more than one worksheet.
    Regards
    Marcus

  • Error occurs while generating the Query

    Hi Experts,
    When I am trying to generate the Query, an error message is displayed as ' Error in generated report (Selection screen is too large) '.
    Query is develoed using Quick list viewer.
    Need ur assistance to overcome the Error.

    hi,
    Try to remove some fields from selection screen as well as output and check.

  • Need to generate the report to get changed and newly added record.....

    Hi Experts,
    I am loading data to cube with full update, now I need to generate the report to get the changed and newly added records based on the date.
    Is it possible????
    If it's possible, how can I achieve this?????
    Please help me.....
    Thanks in advance,
    Venakt.

    I am loading data to cube with full update, now I need to generate the report to get the changed and newly added records based on the date.
    what you mean by based on date??
    When ever the data is refereshed in targets that will be reflected in reports provided if you dont have any aggreagates...if you have then you need to do rollup activity..

  • Need to save the query under the correct role

    Hi Experts,
    I need to save the query under the specific role. So is there anyway to find the query location by role??
    Thanks
    Regards,
    Arpan

    Hi,
    RSZCOMPDIR --> RSRREPDIR -->AGR_HIER
    From RSZCOMPDIR get all the entries of queries.
    compid is query name, take compuID and pass to RSRREPDIR.
    get genuniid and pass to AGR_HIER's sap_guid.
    AGR_NAME in AGR_HIER is role name.
    please check this.
    -Sriram
    Message was edited by: Sriramvijay R
    Message was edited by: Sriramvijay R

  • Help in generating the query

    Hi All,
    I have the below requirement.
    Master table:
    Product ID      Product Name
    1               TV
    2               Cellphone
    3               Laptop
    4               DVD Player
    Details table:
    Product ID     Spec type     Spec Detail
    1               Color          Blue
    1               Weight          20
    2               Color          Blue
    2               Weight          20
    3               Color          Blue
    3                Weight          25
    4               Color          Blue
    4               Weight          20
    4               Height          10Im looking for a way to identify the products that has exact same specifications.
    ie., in the above example TV and Cellphone has the exact specifications.
    So the output of the query should be TV and Cellphone here.
    Is it possible to do in a query or we need to have some sql block to perform this action.
    Any help would be greatly appreciated.
    Thanks,
    Agathya

    Hi agathya,
    We don't know how you would like to handle the situation where more than two products have the same specifications, so I extended your sample data a bit to reflect that situation as well:
    SQL> create table products (id,name)
      2  as
      3  select 1, 'TV' from dual union all
      4  select 2, 'Cellphone' from dual union all
      5  select 3, 'Laptop' from dual union all
      6  select 4, 'DVD Player' from dual union all
      7  select 5, 'Radio' from dual union all
      8  select 6, 'VCR' from dual
      9  /
    Tabel is aangemaakt.
    SQL> create table product_specifications (product_id,spec_type,spec_detail)
      2  as
      3  select 1, 'Color' , 'Blue' from dual union all
      4  select 1, 'Weight', '20'   from dual union all
      5  select 2, 'Color' , 'Blue' from dual union all
      6  select 2, 'Weight', '20'   from dual union all
      7  select 3, 'Color' , 'Blue' from dual union all
      8  select 3, 'Weight', '25'   from dual union all
      9  select 4, 'Color' , 'Blue' from dual union all
    10  select 4, 'Weight', '20'   from dual union all
    11  select 4, 'Height', '10'   from dual union all
    12  select 5, 'Color' , 'Blue' from dual union all
    13  select 5, 'Weight', '20'   from dual union all
    14  select 6, 'Color' , 'Blue' from dual union all
    15  select 6, 'Weight', '20'   from dual union all
    16  select 6, 'Height', '10'   from dual
    17  /
    Tabel is aangemaakt.
    SQL> select p1.name
      2       , p2.name
      3    from products p1
      4       , products p2
      5       , product_specifications ps1
      6       , product_specifications ps2
      7   where p1.id = ps1.product_id
      8     and p2.id = ps2.product_id
      9     and p1.id < p2.id
    10   group by p1.id
    11       , p1.name
    12       , p2.id
    13       , p2.name
    14  having sqrt(count(*)) =
    15         count(case when ps1.spec_type = ps2.spec_type and ps1.spec_detail = ps2.spec_detail then 1 end)
    16  /
    NAME       NAME
    TV         Cellphone
    TV         Radio
    Cellphone  Radio
    DVD Player VCR
    4 rijen zijn geselecteerd.But why on earth did you or your predecessor model product specifications like this? You are making it far more complicated than it needs to be. And the datatype of height and weight should not be the same as for color. But now they are. And how do you restrict the allowable values for colors? Color, weight and height are attributes of your products so they should have been modeled like that.
    See how easy your questions becomes after remodeling it:
    SQL> drop table product_specifications purge
      2  /
    Tabel is verwijderd.
    SQL> drop table products purge
      2  /
    Tabel is verwijderd.
    SQL> create table products (id,name,color,weight,height)
      2  as
      3  select 1, 'TV', 'Blue', 20, null from dual union all
      4  select 2, 'Cellphone', 'Blue', 20, null from dual union all
      5  select 3, 'Laptop', 'Blue', 25, null from dual union all
      6  select 4, 'DVD Player', 'Blue', 20, 10 from dual union all
      7  select 5, 'Radio', 'Blue', 20, null from dual union all
      8  select 6, 'VCR', 'Blue', 20, 10 from dual
      9  /
    Tabel is aangemaakt.
    SQL> select * from products
      2  /
            ID NAME       COLO     WEIGHT     HEIGHT
             1 TV         Blue         20
             2 Cellphone  Blue         20
             3 Laptop     Blue         25
             4 DVD Player Blue         20         10
             5 Radio      Blue         20
             6 VCR        Blue         20         10
    6 rijen zijn geselecteerd.
    SQL> select p1.name
      2       , p2.name
      3    from products p1
      4       , products p2
      5   where p1.id < p2.id
      6     and ( p1.color = p2.color or (p1.color is null and p2.color is null))
      7     and ( p1.weight = p2.weight or (p1.weight is null and p2.weight is null))
      8     and ( p1.height = p2.height or (p1.height is null and p2.height is null))
      9  /
    NAME       NAME
    TV         Cellphone
    TV         Radio
    Cellphone  Radio
    DVD Player VCR
    4 rijen zijn geselecteerd.Hope this helps.
    Regards,
    Rob.

  • Need Help in tuning of the query

    Hi all,
    Can any body help me how we can rewrite this query in
    optimized way.
    SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
    FROM A,B
    WHERE A.C1 IN (
    SELECT COLUMN_1 FROM(
    (SELECT A.C1 AS COLUMN_1,
    COUNT(C1) AS COUNT,
    RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
    FROM A, B, C
    WHERE A.C1 = B.C3
    AND B.C2 = C.C1
    AND <other conditions>
    GROUP BY A.C1)
    WHERE RANK <= 10)
    AND A.C1 = B.C3
    AND <other conditions>
    ORDER BY A.C1
    I am using <other conditions> are same in outer query and inner query also.
    Thanks in Advance,

    Hi,
    Yes exactly I am looking TOP-10 results the query is like this
    SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
    FROM A,B
    WHERE B.C2 IN (
    SELECT COLUMN_1 FROM(
    (SELECT B.C2 AS COLUMN_1,
    COUNT(A.C1) AS COUNT,
    RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
    FROM A, B, C
    WHERE A.C1 = B.C3
    AND B.C2 = C.C1
    AND <other conditions>
    GROUP BY B.C2)
    WHERE RANK <= 10)
    AND A.C1 = B.C3
    AND <other conditions>
    ORDER BY B.C2
    Thanks

  • Help required in generating the following query

    Hi all,
    i need solution regarding the following problem.
    we got many number of groups ,each group containg many number of names,each name containing some items under that
    i had written a query stating that select item where grp  =[0%] and name =[1%] from a table
    it will execute and dispaly a window with two fields at the first field i entered group and in the second field when i select for existing values it shows all the items of all groups
    but we need only items that belong to the group that we enter in the first field
    any one tell me the query regarding this requirement

    HI,
    The alternative solution is: develop your add-on, which get the filtering window, and connects the 2 parameters inside, then runs the query and displays it in a matrix/Grid.
    It is not takes so many time.
    Regards,
    J.

  • Need help to re-format the query

    Hi All,
    Could any one please help me to rewrite this query or explain me how to do it as it is taking 20 mins to execute....
    SELECT
    AC.ACC_NO||DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.PAYMENT_SET      
                                       FROM
            MIF LMI2 WHERE LMI2.MID =
            (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID= MI.MID AND RELATION='ROF')),MI.PAYMENT_SET)||
            DECODE(MI.MSG_CLASS,'ROF', (SELECT LMI2.SERVICE FROM MIF LMI2 WHERE LMI2.MID = (SELECT CHILDMID FROM
      MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),MI.SERVICE) HASH_KEY,
      MI.MID ,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.PAYMENT_SET FROM MIF LMI2
      WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
      RELATION='ROF')),MI.PAYMENT_SET) PAYMENT_SET,
      MI.AMOUNT,
      NVL(DECODE(MI.MSG_CLASS,'ROF',MI.CRAMOUNT, MI.DBAMOUNT) ,0) AMT,
      AC.ACC_NO,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.BATCH_COMPANY_CD FROM MIF LMI2 WHERE
      LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
      RELATION='ROF')),MI.BATCH_COMPANY_CD) BATCHCOMP,
      AC.ACC_ALIAS, NVL(AC.IBAN,
      NVL(AC.ACC_ALIAS,AC.ACC_NO)) IBAN_ACCNO,
      AC.CURRENCY , AC.ACCOUNTNAME ,
      CASE
           WHEN (SIGN(MI.PROCESS_DT - TO_DATE(:B2 ,'YYYYMMDD'))) = '1'
           THEN 'F'
           ELSE 'C' END FUTURE_IND,
           (CASE
                WHEN (MI.MSG_STATUS = 'CANCELED' OR   MI.STATBFHELD = 'CANCELED')
                THEN 'C'
                WHEN MI.BATCH_PAYMENT_TP = 'RMTRT'
                THEN 'R'
                WHEN (MI.REJECT_RETURN='REJT' OR MI.MSG_CLASS = 'ROF' OR MI.MSG_STATUS = 'REJECTED')
                THEN 'A'
                WHEN (MI.REJECT_RETURN='RETN' OR (MI.BATCH_PAYMENT_TP='RTACH' AND MSG_CLASS='ROF'))
                THEN 'B'
                WHEN  MI.MSG_STATUS='FORWARD_PROCESSING'
                THEN 'F'
                WHEN (MI.MSG_STATUS NOT IN  ('COMPLETE','CANCELED','REJECTED') OR (MI.MSG_STATUS='AGED' AND
                     MI.STATBFHELD NOT IN ('COMPLETE','CANCELED','REJECTED')) )
                THEN 'U'
                WHEN  MI.PROCESS_DT = TO_DATE(:B2 ,'YYYYMMDD')
                THEN 'P' END)
      PAY_STATUS,
      MT.DB_FEE_ACCOUNT_CCY,
      (SELECT MESSAGEFREETEXT.CONTENTS
           FROM
           MESSAGEFREETEXT
           WHERE
                FIELDNAME ='MANDATEREFERENCE'
                     AND MESSAGEFREETEXT.MID= MI.MID) MANDREF,
      (SELECT MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT
           WHERE FIELDNAME ='DIRECT_DEBIT_REFERENCE' AND MESSAGEFREETEXT.MID=MI.MID)  DDREF,
      MT.CUSTOMER_BATCH_REFERENCE LOCINFO,
      (SELECT  MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT WHERE FIELDNAME =  'SECOND_PARTY_ID' AND MESSAGEFREETEXT.MID=MI.MID) SECPRTYINF,
      (SELECT  MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT WHERE FIELDNAME = 'HUB_PAY_PROD_TYP' AND MESSAGEFREETEXT.MID=MI.MID) PAYPRODTYP,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.CHANNEL_REFERENCE FROM MIF LMI2
                          WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
                                         RELATION='ROF')),MI.CHANNEL_REFERENCE) CHNREF,
      (SELECT  MESSAGEFREETEXT.CONTENTS
           FROM MESSAGEFREETEXT
           WHERE FIELDNAME =  'CHN_BATCH_REF' AND MESSAGEFREETEXT.MID=MI.MID) CHNBATREF,
      TO_CHAR(DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.VALUE_DATE FROM MIF LMI2
                     WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
                                    RELATION='ROF')),MI.VALUE_DATE),'DD/MM/YYYY') VALUEDT,
      DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.ORIG_REFERENCE FROM MIF LMI2 WHERE LMI2.MID = (SELECT
                          CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),
                                                        MI.ORIG_REFERENCE) ORIGREF,
      CASE
           WHEN (MI.OFFICE <> MI.ORIG_OFFICE)
           THEN MT.DR_SIDE_RATE_AM
           ELSE
                CASE
                     WHEN MI.DBCURRENCY = MI.CRCURRENCY
                     THEN
                          CASE
                               WHEN MI.CRCURRENCY = :B4
                               THEN MT.DR_RATE ELSE MT.CR_RATE
                          END
                     ELSE
                          CASE
                               WHEN   MI.CRCURRENCY = :B4
                               THEN MT.DR_RATE ELSE MT.CR_RATE
                          END
                END
           END EXCHRT,
      MT.BBK_ADDR1,
      MT.BBK_ADDR2,
      MT.BBK_ADDR3 ,
      MT.BBK ,
      MT.BNF_ADDR1,
      MT.BNF_ADDR2,
      MT.BNF_ADDR3,
      MT.BNF_ADDR4 ,
      MT.BNF ,
      DECODE(MT.BNF_IDCODE,'AC',MT.BNF_ID,' ') ORGBNFID,
      DECODE(NVL(MI.ORIG_INSTRUCT_AMOUNT,0),0, MI.ORIG_AMOUNT) ORGINSTAMT,
      NVL(TRIM(MI.ORIG_INSTRUCT_CURRENCY),  MI.ORIG_CURRENCY) ORGINSTCUR,
      CASE
           WHEN MOP LIKE 'DRFT%'
           THEN 'DD'
           WHEN MOP   LIKE 'CHEQ%'
           THEN 'CO'
           WHEN MOP LIKE 'SWIFT'
           THEN 'TT'
           WHEN MOP LIKE 'DDP%'
           THEN 'T'
           WHEN MOP LIKE 'BOOK'
           THEN 'T' ELSE 'LP'
      END PYMTTP,
      MT.OBI ,
      TO_CHAR(MI.PROCESS_DT,'YYYYMMDD') PROCESSDT,
      MI.REFERENCE,
      MT.BBK_BIC,
      MT.BBK_IDCODE,
      DECODE(MT.BBK_IDCODE,'AC',' ',SUBSTR(MT.BBK_ID,1,12)) BBKID,
      MI.LOCAL_REF,
      MI.CURRENCY INDCURR,
      MI.MSG_STATUS,
      MI.PK_BATCH_SUBSET,
      TO_CHAR(SBBATCH.PROCESS_DT,'YYYYMMDD') SBPROCESSDT,
      DECODE(MI.MSG_CLASS,'ROF',MI.CRCURRENCY, MI.DBCURRENCY) DBCURR,
      MI.ORIG_REFERENCE ORIGREFRET
      FROM
           MIF MI,
           MTF1000 MT,
           ACCOUNTS AC,
           (     SELECT
                     MF.PK_BATCH_SUBSET,
                     MF.PROCESS_DT,
                     MTF.ORG_ID,
                     MTF.MP_CR_ACC,
                     MTF.CR_ACC_NO
                FROM
                     MIF MF,
                     MTF1000
                     MTF
                WHERE
                     ((MSG_STATUS IN ('COMPLETE','CANCELED','REJECTED')) OR
                     (MSG_STATUS = 'AGED' AND STATBFHELD IN ('COMPLETE','CANCELED','REJECTED')))
                AND
                     BATCH_MSG_TP = 'S' AND MF.MID = MTF.MID )
           SBBATCH
      WHERE
           MI.MSG_TYPE =   :B3
      AND MI.PROCESS_DT = TO_DATE(:B2 ,'YYYYMMDD')
      AND MI.BATCH_MSG_TP = 'I'
      AND DECODE(MI.MSG_CLASS,'ROF',
           (SELECT LMI2.SERVICE FROM MIF LMI2 WHERE LMI2.MID =
           (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),MI.SERVICE)
           IN ('NET','HCN','BIB','LST','MRI')
      AND MI.PK_BATCH_EXCH IN (SELECT PK_BATCH_EXCH FROM BATCH_EXCH)
      AND MI.MID = MT.MID
      AND SBBATCH.PK_BATCH_SUBSET = MI.PK_BATCH_SUBSET
      AND TRIM(DECODE(MI.MSG_CLASS,'ROF',MT.CR_ACC_NO, NVL(MT.ORG_ID,NVL(MT.MP_DB_ACC,MT.ACC_NO))) )=AC.ACC_NO
      AND AC.OFFICE = :B1
      ORDER BY HASH_KEY,PAY_STATUS

    Hi,
    please try this.
    The first decode or at least part of it repeats at least 7 times.
         DECODE(MI.MSG_CLASS,'ROF',
                                         (SELECT LMI2.PAYMENT_SET  
                                    FROM MIF LMI2 WHERE LMI2.MID =
          (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')
                                            ),MI.PAYMENT_SET
                   ||
        DECODE(MI.MSG_CLASS,'ROF',
                                         (SELECT LMI2.SERVICE
                                                                                 FROM MIF LMI2 WHERE LMI2.MID =
                   (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')
                                             ),MI.SERVICE) HASH_KEY,
    is similar to this
    select mif.* from mif, mfamily where mif.mid=mfamily.childmid
    and relation = 'ROF' and msg_class='ROF'
    insert it as an inline view and add a conditition
    from ...
    (select mif.* from mif, mfamily where mif.mid=mfamily.childmid
    and relation = 'ROF' and msg_class='ROF') rof
    Where ...
    and mi.mid=Rof.mid (+)...
    and your code above would look like
    nvl(rof.payment_set,mi.payment_set) || nvl(rof.service,mi.service) HASH_KEY,
    nvl(rof.payment_set,mi.payment_set) PAYMENT_SET
    replace all the same decode above with corresponding nvl(...)Hope this helps.

  • Help need to create a query

    I need to fetch records from a table. Please help me to create a query
    The Tablename is Employee. It has the following records
    Department Empname Gender
    Finance Tom Male
    Finance Rick Male
    Finance Stacy Female
    Corporate Tom Male
    Corporate Rob Male
    I want to select the value of the Gender field from the Employee table corresponding to a Department
    If all the values in the Gender field are 'MALE' corresponding to 'finance' in the Department field, the value should be 'MALE'
    If there is a value 'FEMALE', the gender corresponding to the Empname 'TOM' should be considered as the gender

    Tables have rows - not records.
    Your question is a basic SQL language question - which means you do not know the SQL language. This forum is not a classroom for teaching you the SQL language.
    Use the following as the basic outline of how your SQL language statement need to look like for selecting the required from the table:
    SELECT
      <<sql projection goes here>>
    FROM <<table name goes here>>
    WHERE <<filter conditions go here>>
    {code}
    The SQL projection specifies the list of columns the SQL need to return to the caller.
    The filter condition is basic predicates and AND and OR  can be used for multiple predicates.
    Go to http://tahiti.oracle.com and look for the +SQL Reference Guide+ for the Oracle version you are using. The +SELECT+ statement syntax is covered in detail and sample statements are provided.
    And please do not expect this forum to be used as a classroom, or expect this forum to do your homework for a class.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help needed in tuning this query

    This is the SQL i would like to tune for performace...
    The table structure is given below.
    The table has about 2 million rows.
    From the second day onwards only around 10% of records will be between Load_Start_Time and Load_End_Time. Among these around 50% will have THAMES_URN_WITH_ROLE_SUFFIX as 'TP%'. At present there are unique and primary key indexes on THAMES_URN_WITH_ROLE_SUFFIX .
    I'm sure that we need a b-tree index on STG_UPDATE_DATE_TIME as it is the column with good selectivity.
    I'm primarily concerned about the substr, instr and reverese on THAMES_URN_WITH_ROLE_SUFFIX.
    Also pls. let me know if the order of predicates is right.
    Thanks in advance.
    SELECT TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN, TPD_STG_TL_SF_LEGAL_OWNER.UPDATE_SOURCE, TPD_STG_TL_SF_LEGAL_OWNER.SOURCE_EXTRACT_DATE_TIME, TPD_STG_TL_SF_LEGAL_OWNER.LEGAL_OWNERSHIP_ISSUE_IND, TPD_STG_TL_SF_LEGAL_OWNER.CONTACTABLE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ADMIN_CONTROL_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.BANKRUPTCY_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.ASSIGNED_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.IN_TRUST_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.DIVORCE_CASE_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.POA_COP_INDICATOR, TPD_STG_TL_SF_LEGAL_OWNER.CLEANSING_STATUS, TPD_STG_TL_SF_LEGAL_OWNER.CATEGORY
    FROM
    TPD_STG_TL_SF_LEGAL_OWNER
    WHERE
    ((TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME > '$$Load_Start_Time'
    AND
    TPD_STG_TL_SF_LEGAL_OWNER.STG_UPDATE_DATE_TIME <= '$$Load_End_Time')
    OR
    (TPD_STG_TL_SF_LEGAL_OWNER.TPDB_PROCESSED_IDENTIFIER != 'Y') )
    AND
    SUBSTR(TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX,1,2)='TP'
    AND
    SUBSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),INSTR(REVERSE( TPD_STG_TL_SF_LEGAL_OWNER.THAMES_URN_WITH_ROLE_SUFFIX),'-',1)-1,1)!='S'
    ========================================
    CREATE TABLE TPD_STG_TL_SF_LEGAL_OWNER
    THAMES_URN VARCHAR2(35 BYTE) NOT NULL,
    UPDATE_SOURCE VARCHAR2(3 BYTE),
    SOURCE_EXTRACT_DATE_TIME DATE,
    LEGAL_OWNERSHIP_ISSUE_IND CHAR(1 BYTE),
    CONTACTABLE_INDICATOR CHAR(1 BYTE),
    ADMIN_CONTROL_INDICATOR CHAR(1 BYTE),
    BANKRUPTCY_INDICATOR CHAR(1 BYTE),
    ASSIGNED_INDICATOR CHAR(1 BYTE),
    IN_TRUST_INDICATOR CHAR(1 BYTE),
    DIVORCE_CASE_INDICATOR CHAR(1 BYTE),
    POA_COP_INDICATOR CHAR(1 BYTE),
    THAMES_URN_WITH_ROLE_SUFFIX VARCHAR2(39 BYTE),
    THAMES_LEGAL_OWNERSHIP_IND CHAR(1 BYTE),
    PRODUCT_HOLDING_ROLE_TYPE VARCHAR2(21 BYTE),
    OWNERSHIP_SPLIT_PERCENTAGE NUMBER(3),
    SOURCE_SYSTEM VARCHAR2(3 BYTE),
    TITLE VARCHAR2(50 BYTE),
    FIRST_NAME VARCHAR2(50 BYTE),
    MIDDLE_INITIAL VARCHAR2(50 BYTE),
    SURNAME VARCHAR2(50 BYTE),
    GENDER CHAR(1 BYTE),
    BIRTH_DATE DATE,
    DEATH_INDICATOR CHAR(1 BYTE),
    DEATH_RECORD_DATE DATE,
    NATIONAL_INSURANCE_NUMBER VARCHAR2(9 BYTE),
    GONE_AWAY_INDICATOR CHAR(1 BYTE),
    ADDRESS_LINE_1 VARCHAR2(50 BYTE),
    ADDRESS_LINE_2 VARCHAR2(50 BYTE),
    ADDRESS_LINE_3 VARCHAR2(50 BYTE),
    ADDRESS_LINE_4 VARCHAR2(50 BYTE),
    ADDRESS_LINE_5 VARCHAR2(50 BYTE),
    POST_CODE VARCHAR2(12 BYTE),
    COUNTRY VARCHAR2(50 BYTE),
    OVERSEAS_ADDRESS_INDICATOR CHAR(1 BYTE),
    ORGANISATION_NAME VARCHAR2(50 BYTE),
    TPDB_PROCESSED_IDENTIFIER CHAR(2 BYTE),
    CLEANSING_STATUS VARCHAR2(30 BYTE),
    CATEGORY VARCHAR2(50 BYTE),
    SCHEME_NAME VARCHAR2(50 BYTE),
    STG_CREATE_DATE_TIME DATE,
    STG_UPDATE_DATE_TIME DATE,
    LAST_UPDATED_DATE_TIME DATE
    TABLESPACE TPDBS01A_DATA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE UNIQUE INDEX TPD_STG_TL_SF_LEGAL_OWNER_PK ON TPD_STG_TL_SF_LEGAL_OWNER
    (THAMES_URN_WITH_ROLE_SUFFIX)
    LOGGING
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    NOPARALLEL;
    ALTER TABLE TPD_STG_TL_SF_LEGAL_OWNER ADD (
    CONSTRAINT TPD_STG_TL_SF_LEGAL_OWNER_PK
    PRIMARY KEY
    (THAMES_URN_WITH_ROLE_SUFFIX)
    USING INDEX
    TABLESPACE TPDBS01A_DATA
    PCTFREE 10
    INITRANS 2
    MAXTRANS 255
    STORAGE (
    INITIAL 128K
    NEXT 128K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    ));

    > If indexes don't help, is the only way to gain REAL
    performance gain on this type of query is to
    partition the table
    If a Full Table Scan on a table takes "too long" (and
    this is purely subjective - "too long" is different
    for every problem) and indexes can't help, and we
    need <100% of the rows, and if partitioning will give
    us the performance we desire, is it OK do it ? Also
    would STG_UPDATE_DATE_TIME be the best column to do a
    index partion ?
    For this type of query, partitioning on STG_UPDATE_DATE_TIME would be good.
    However, partitioning is not done just for one query. It has to fit in your total design. For example, if you are also doing queries with a predicate like <column with a local unique index but not the partition key> = <constant>, it would have to visit all partitions instead of just one, and those queries would take much longer to execute. You can make the index global, but there all kind of maintenance issues with that. In short: be careful about partitioning and think it through first.
    > But is it a good option to partition tables with
    total no. of rows between 2 million and 5 million ? I
    thought partitioning is better done for tables > 20
    million.
    Please throw some light on that.
    Generally, partitioning is done on bigger tables, yes. But it is not about some specific number of rows. You partition a table when all forecasted use of the table is known, so you can make a good judgement which usages will benefit, which ones won't be affected and which ones are likely to suffer. When the benefits outweigh the disadvantages, you partition...
    Above I had an example about queries that are going to suffer. Partitioning is beneficial for example when once in some period you'd have to delete A LOT of old rows. Or when you have some data warehousing queries that need like 10% of only the most recent data in a huge table.
    The decision is yours.
    Regards,
    Rob.

  • Help needed in writing a query

    Hi all,
    Following is the structure of my table.
    Data
    Key Number
    Id Number
    Value varchar2(100)
    activity_name varchar2(100)
    Creation_Date Date
    Eval_Point varchar2(100)
    In the above table Id is the primary key.
    The column eval_point holds only two types of entries 'activation' or 'completion'
    The activity_name column holds the name of the activity.
    The sample entries in the table are as follows
    Key Value activity_name Creation_Date Id Eval_Point
    260002 XXX assign_1 2007-09-21 16:58:41.920000 951 activation
    260002     XXX assign_1 2007-09-21 16:58:43.392000 953     completion
    260002     XXX assign_2 2007-09-21 16:59:03.732000 956     activation
    260002     XXX assign_2 2007-09-21 16:59:04.112000 954     completion
    260002     XXX assign_3 2007-09-21 16:59:24.331000     958     activation
    260002     XXX assign_3 2007-09-21 16:59:24.421000     957     completion
    i need to write a query which gives me data in the following format
    value id start_date end_date
    XXX YYY 2007-09-21 16:58:41.920000 2007-09-21 16:58:43.392000
    where start_date is the creation date of the 'activation' and end_date is the creation_date of 'completion'.
    Can somebody help?
    -thanks
    lavanya

    hello all,
    I would like to re frame my question.
    this is the output of the base query
    select id,instance_key,sensor_target,activity_sensor,creation_date,eval_point from bpel_variable_sensor_values where instance_key=260002;
    953     260002     Assign_1     952     2007-09-21 16:58:43.392000     completion
    951     260002     Assign_1     952     2007-09-21 16:58:41.920000     activation
    956     260002     Assign_2     955     2007-09-21 16:59:03.732000     activation
    954     260002     Assign_2     955     2007-09-21 16:59:04.112000     completion
    958     260002     Assign_3     959     2007-09-21 16:59:24.331000     activation
    957     260002     Assign_3     959     2007-09-21 16:59:24.421000     completion
    962     260002     Assign_4     960     2007-09-21 16:59:44.741000     completion
    961     260002     Assign_4     960     2007-09-21 16:59:44.640000     activation
    964     260002     Assign_5     965     2007-09-21 17:00:05.290000     completion
    963     260002     Assign_5     965     2007-09-21 17:00:04.950000     activation
    I am trying out this query
    select a.instance_key,a.creation_date,b.creation_date,a.id
    from bpel_variable_sensor_values a, bpel_variable_sensor_values b
    where a.instance_key=b.instance_key
    and a.instance_key=260002
    and a.eval_point='activation'
    and b.eval_point='completion'
    and i am getting 25 entries i.e a cartesian product of a.creation_date
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:58:43.392000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:04.112000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:24.421000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 16:59:44.741000     951
    260002     2007-09-21 16:58:41.920000     2007-09-21 17:00:05.290000     951
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:58:43.392000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:04.112000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:24.421000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 16:59:44.741000     956
    260002     2007-09-21 16:59:03.732000     2007-09-21 17:00:05.290000     956
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:58:43.392000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:04.112000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:24.421000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 16:59:44.741000     958
    260002     2007-09-21 16:59:24.331000     2007-09-21 17:00:05.290000     958
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:58:43.392000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:04.112000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:24.421000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 16:59:44.741000     961
    260002     2007-09-21 16:59:44.640000     2007-09-21 17:00:05.290000     961
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:58:43.392000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:04.112000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:24.421000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 16:59:44.741000     963
    260002     2007-09-21 17:00:04.950000     2007-09-21 17:00:05.290000     963
    can soembody help me to reduce these to 5 rows.

Maybe you are looking for

  • How can I transfer my iphone music to my itunes library?

    I got a new laptop and I still have my music on my iphone but since my itunes library is empty I want my music to sync. But I can't figure it out. HELP ME ps - I have a mac laptop and iphones 4s

  • Premiere Elements 12 crashing in Windows 7

    After starting Premiere Elements 12, it crashes randomly. No error code, no BSOD. Just a message from Windows saying that the program has stopped working. The program says it is up to date, and I've updated everything from Windows to Java to Flash an

  • 'authentication control-direction in' in authentication CLOSED mode

    Switch: 4510R+E, running a DEV version based off 3.6.0 ISE: 1.2.0.899 patch 7 Hi, I have been working on a weird issue where some of my clients would randomly drop their IP address and the only way I could get it back was to move their port to authen

  • R/3-- XI,   queue stuck problem,  concept not clear

    Hi Forum, I have a R/3(abap proxy)----->XI scenario, now the data being sent from R/3 to XI is getting stuck (due to some HTTP error) in the queue, which is visibale through tcode SMq2 of R/3, I want to know, why the stuck queue and hence the LUW is

  • Finding and fixing block corruption in oracle 10g

    10.2.0.5.6 OS: Hp-unix databases files on RAW. DB Size: 10 TBs+ We had a SAN outage recently. The DB is back online. We want to check for block corruption to be on the safe side. We are planning to take a SAN EMC BCV copy of prod to run this. Looking