How to do this in a query

Hello All
I have value like these in a table
Id Id_num Date
1 PR 10-Jun-2004
1 PF 10-Jun-2005
2 PF 10-Jun-2005
3 PR 10-Jun-2005
Output shoud be
1 PF 10-Jun-2005
2 PF 10-Jun-2005
3 PR 10-Jun-2005
ie. If a ID has ID_NUM values with PF and PR, then PF should be picked
If PF is not present then the PR value should be taken
Pls help

Many options, including:
select * from id_test t1
where id_num='PF'
or (id_num='PR' and not exists (select 1 from id_test t2 where t1.id = t2.id and t2.id_num='PF'))
select id, id_num, id_date from (
select t.*,row_number() over (partition by id order by decode(id_num,'PF',1, 2) ) rn from id_test t
) where rn=1

Similar Messages

  • How to Achieve this in SQL Query?

    How to Achieve this ?
    I have a table with numeric value populated like this
    create table random_numeral (numerals Number(10));
    insert into random_numeral values (1);
    insert into random_numeral values (2);
    insert into random_numeral values (3);
    insert into random_numeral values (4);
    insert into random_numeral values (5);
    insert into random_numeral values (6);
    insert into random_numeral values (56);
    insert into random_numeral values (85);
    insert into random_numeral values (24);
    insert into random_numeral values (11);
    insert into random_numeral values (120);
    insert into random_numeral values (114);
    Numerals
    1
    2
    3
    4
    5
    6
    56
    85
    24
    11
    120
    114
    I want to display the data as follows
    col1 / col2 / col3
    1 / 2 / 3
    4 / 5 / 6
    11 / 24 / 56
    85 / 114 / 120
    Can anyone Help me?

    I hope there might be some simple way to do this and waiting for experts to reply.
    Try the below query.
    SQL> select * from random_numeral;
      NUMERALS
             1
             2
             3
             4
             5
             6
            56
            85
            24
            11
           120
      NUMERALS
           114
           100
           140
    14 rows selected.
    SQL> select a.numerals ||' / '||b.numerals||' / '||c.numerals from
      2          (select numerals,rownum rn1 from
      3          (
      4              select numerals,mod(row_number() over(partition by 1 order by numerals),3)
      5              from random_numeral
      6          )
      7          where rn=1) a,
      8          (select numerals,rownum rn1 from
      9          (
    10              select numerals,mod(row_number() over(partition by 1 order by numerals),3)
    11              from random_numeral
    12          )
    13          where rn=2) b,
    14          (select numerals,rownum rn1 from
    15          (
    16              select numerals,mod(row_number() over(partition by 1 order by numerals),3)
    17              from random_numeral
    18          )
    19          where rn=0) c
    20  where   a.rn1=b.rn1(+)
    21  and b.rn1=c.rn1(+)
    22  /
    A.NUMERALS||'/'||B.NUMERALS||'/'||C.NUMERALS
    1 / 2 / 3
    4 / 5 / 6
    11 / 24 / 56
    85 / 100 / 114
    120 / 140 /
    SQL>Cheers,
    Mohana

  • How to Perform this calculaction in Query

    Hi Experts
    How can i achieve this Calculaction at query Level.
    Data:
    Emp_ID--Wage_IDPayroll_Date--Amount
    1--03925.01.2008-5000
    1--03925.02.2008-5000
    1--03925.03.2008-5000
    1--03925.04.2008-6000
    1--03925.07.2008-6000
    The employee will have No of different Wage types in his pay run.
    But as per my requirment i want to calculacte Employee Salarly.
    Lets Consider Wage Type 039 which is Salarly
    The Cal i need to perform is
    Select the Wage Type 039 and then Select the Latest (25.07.2008) Payroll date and then select the amount assiociated with it for and the 12* amount give salarly
    In the above case aslarly should be 72,000

    Hi,
    Soluition can be the following:
    Put Pay_Roll_date also as a key-figure in your cube and add to columns.
    Add condition (top 1) on keyfigure,
    In Character Assignment tick ïndividual char. and Char combinations.
    Tick also Emp_id and Wage ID. do not tick Pay_Roll_date (the characteristics, not the keyfigure)
    Hide key-figure Pay_roll_date & Amount
    Make calculated keyfigure Salary = 12 * Amount.
    That should do it.
    Udo

  • How to put this condition in Query

    Dear experts,
    I have a scenario where in the calculation should be dynamic between key figures in query
    For example i have a
    Target Cost and Actualcost1, Actualcost2, Actualcost3
    i need to findout the variance between the Target and Actual
    but the catch is that i need to findout the variance with the latest actual cost
    1. )  Target cost = 100
    Actual cost1=10, Acutal cost2=0, actual cost3=0
    then the formula should be Actual cost1-target cost
    2. )But if
    Target cost  =100
    Actual cost1=10, Actual cost2=5, Actual cost3=0
    then the formula should be Actual cost2- Target cost
    3. Target cost =100
    Actual cost1=10, Actual cost2 = 5, Actual cost3= 15
    then the formula should be Actual Cost3-Target cost
    How to achieve this
    Thanks and regards
    Neel

    Hi Neel,
    Do you have indicator saying that a particular actual cost is the latest? If you have any indicator thsi would make the job easy. Else you need to create new formulas to derive the logic.
    Else you can proceed with the belwo logic.
    1.target cost
    2. Actual Costs 1 - Hide
    3. Actual Costs 2 - Hide
    4. Actual Costs 3 - Hide
    5. New formula whcih evaluates the latest.
    Write the condition
    If Actual costs3 = 0 and actual cost2 = 0 then actual cost1.
    else if actual cost2= 0 then actual cost1
    else if actual cost1 NE 0 and actual cost2 NE 0 then Actual cost3.
    Then hide the above new formula.
    And in a new formula you can find the diff between the Target cost and the latest cost derived in teh above new formula.
    If the conditions is too big in the above new formula, you can split across two three new formulas and derive the logic.
    Just make some changes to the above logic if it is not 100%.
    I believe this logic will work.

  • How to do this with one query?

    here is the basic query
    <cfquery name="getCenturies"
    datasource="#application.dsn#">
    SELECT riderId, rideDistance, rideDate
    FROM mileageLog
    WHERE rideDistance > 99
    </cfquery>
    and my results would be something like
    Kevin 114
    Chris 103
    Kevin 100
    Don 102
    Kevin 106
    Now how can I get the count for each person
    Kevin 3
    Chris 1
    Don 1

    jkgiven wrote:
    > I appreciate your help
    >
    > taking a look at your suggestion, the >99 part needs
    to refer to the
    > rideDistance column (the 114, 103, 100, 102, 106) thus
    the greater than 99
    > amounts. And how would I refer to each rider count total
    (Kevin 3, Chris 1, Don
    > 1)
    >
    > I reworked the quety to this... but still no go
    > SELECT riderId, count(riderId) AS riderCount,
    rideDistance
    > FROM mileageLog
    > GROUP By riderId
    > HAVING rideDistance >99
    >
    > It tells me that rideDistance is not part of an
    aggregate function. I thought
    > to get around this I just had to have each variable
    called for in the SELECT
    > line?
    >
    in the SELECT statement change rideDistance to
    SUM(rideDistance) - i
    think that is what you want to get anyway, isn't it? - and
    you won't get
    that error. it's not the SELECT statement you have to have
    the vars
    listed in; it's either in the GROUP BY or use an aggregate
    function on it..
    Azadi Saryev
    Sabai-dee.com
    Vientiane, Laos
    http://www.sabai-dee.com

  • How to achieve this Calculaction in Query Designer

    Hi Experts
    Could you please update me on How can i acieve this calculaction...
    I had 2 KFs & 1 Formula (% Calculaction) in my Report
    Col A--Col B---Col C (%)-----
    R1----32 50%--
    R2----23(-33%)--
    R3----141217%--
    R4----161060%--
    Over
    all
    Result352729%--
    Col C = Col A % Col B
    In my Query  i had a condition on Col C
    Show Col C >0
    Then output of query is
    Col A--Col B---Col C (%)-----
    R1----32 50%--
    R3----141217%--
    R4----161060%--
    Over
    all
    Result352729%--
    THE OVERRESULT IS NOT CHANGING
    MY requirment is to achieve overresult for above query output
    Over
    all
    Result332437%--
    I can managed to get the Overall result for Col A & Col B in the Properties>Calculactions>Calculate result As-->Total
    What setting i have to make to change Col C Overall result
    Thanks

    Hi,
    I think that deactivating the condition and using a formula instead will work.
    Try e.g. this formula for Col C:
    ( 'Col A' % 'Col B' > 0 ) * ( 'Col A' % 'Col B' )
    You might also want to activate zero suppression in the report.
    Hope it helps.
    BR
    Stefan

  • HOw to achieve this at report/query level

    Hi Experts
    Please update me how can i achieve this at query level
    Lets Consider Data in my Cube
    Dept_id--Date--
    Qty
    -101.01.20093-----
    -101.01.20095-----
    -101.01.20098-----
    -101.01.20091-----
    -101.01.20099-----
    That is how data is avaliable in my cube
    When i run the report the output is displayed as
    Dept_id--Date--
    Qty
    -101.01.200926-----
    That is what it actually do...it will sumirises into one record.....
    BUT
    My requirment is the query result should be ....with out summarisation
    Dept_id--Date--
    Qty
    -101.01.20093-----
    -101.01.20095-----
    -101.01.20098-----
    -101.01.20091-----
    -101.01.20099-----
    Please update me is there any setting i can make at query level

    Hi,
    By default data will be aggregated in Query.
    How come data available in Cube at different aggregation level...? due to request no or some other characteristic which is unique for each record...??
    If some other characteristic available, make it available that characteristic in rows to get desired result.
    Srini

  • How to fix this QtyOnHand FMS query with SO and PO ShipDates.

    Hi Forum,
    I have this query that returns available quantity that takes into account (from PO)  on order and on commit (SO) based on dates of order and receive.
    declare
    @onhand as float,
    @openqty_s_order as float,
    @openqty_p_order as float
    set @onhand = (select oitw.onhand from oitw
    where oitw.whscode = $[$38.24.0] and oitw.itemcode = $[$38.1.0])
    set @openqty_s_order = (select sum(openqty) from rdr1
    where (rdr1.shipdate <= $[$38.25.0]) and (rdr1.itemcode = $[$38.1.0]) and (rdr1.whsCode = $[$38.24.0]))
    set @openqty_p_order = (select sum(openqty) from por1
    where (por1.shipdate <= $[$38.25.0]) and (por1.itemcode = $[$38.1.0]) and (por1.whsCode = $[$38.24.0]))
    select (@openqty_p_order + @Onhand - @openqty_s_order)
    Whenever the SO ShipDate is <= PO Ship Date, the value returned by entire query is 0.0 instead of OnHand - Qty committed by SO's.
    This query works when SO ShipDate is >= PO ShipDate, it returns OnHand-Qty Committed by SOs + Available through POs
    To repeat the problem:
    BASICALLY whenever @openqty_p_order has no value returned then the entire select -> select (@openqty_p_order + @Onhand - @openqty_s_order) returns 0.0, even though @onhand - @openqty_s_order have values that is not zero.
    Appreciate your help. Thank you.

    Hi Syed Aleem,
    Modify the Query as follows :
       Select @OpenQty=isNull(sum(openqty),0)
       From RDR1
       where (rdr1.shipdate <= $[$38.25.0]) and (rdr1.itemcode = $[$38.1.0]) and (rdr1.whsCode = $[$38.24.0]))
       Select @openqty_p_order=isNull(Sum(OpenQty),0)
       from por1
       where (por1.shipdate <= $[$38.25.0]) and (por1.itemcode = $[$38.1.0]) and (por1.whsCode = $[$38.24.0]))
    The problem occurs when there is no row to select then aggregate clause returns NULL which cannot be used in any Operation .
    Hence use isNull function to avoid this error.
    Thanks and Regards,
    Pooja Singh.

  • How to solve this issue in query definition

    Hi Experts,
    I need to solve an issue existed in a query.
    This query is built on a infocube which main char and key figures as follow:
    sales doc., item, material, fiscal year/period, ordered qty, billed qty.
    The query has to show opened qty for specific sales doc / item level. the formula for  opened qty = ordered qty - billed qty. But some of the sales doc /item are partial delivered i.e. there are several deliveries' entries for same sales doc/itm. for example the entries as follow:
    sales doc---- item--materailfiscal year/periodordered qty-- billed qty
    20001------ --    30--- m1 2009/002  200--
      25
    20001--    30 -m1 2009/002 -  200--
    100
    Then after the execution of the query we got the opened qty: (200 - 25) + (200 - 100) = 175. This is totally wrong because the correct opened qty should be 200 - 25 - 100 = 75.
    Could any body provide a solution to get the correct result ?
    Thanks a lot
    Edited by: Leon Ouyang on Dec 15, 2008 4:12 PM
    Edited by: Leon Ouyang on Dec 15, 2008 4:13 PM
    Edited by: Leon Ouyang on Dec 15, 2008 4:43 PM

    Hi Leon,
    Somewhere in your infocube there must be an indicator whether it is the first delivery or not.
    Change ordered quantity into a resctricted keyfigure using the restriction of the indicator first delivery.
    Your overview will be:
    sales doc---- item--materailfiscal year/periodordered qty-- billed qty
    20001------ -- 30--- m1 2009/002 200--
    25
    20001-- 30 -m1 2009/002--
    100
    And your total will be correct.
    Success,
    Udo.

  • Filtering on 0activity - how to achieve this in a query?

    Hi all,
    I have a requirement in my report which is: Give me, of all network numbers, only they keyfigures concering activity 0001.
    In the BEx querydesigner I have 0WBS_ELEMT, 0NETWORK and 0ACTIVITY as characteristics.
    The next step is that I want to filter on a certain activity code, say 0001.
    The only problem is that the key of 0ACTIVITY consists of both 0NETWORK and 0ACTIVITY and I can never select just 0001 as a filter.
    Is there a way to achieve filtering on query level? Or do I have to adapt my model in BW?
    Thanks,
    JW

    Thank you Alexander!
    Well, I found several sub optimal solutions in the query designer.
    One is creating a variable with an offset value to select only the activity code, and using this to create a keyfig z_activity to display just the activity code. Then, you can set a condition on this keyfig to show only certain activity codes.
    Advantage: datamodeling unchanged.
    Disadvantage: high maintenance solution
    The optimal solution seems to be on the BW-side: an option is to define an attribute only z-infoobject and add it to InfoObject 0ACTIVITY, filling via the routine of the InfoObject in the maintenance screen.
    The downside to Alexanders solution is that, by adding it to the InfoProvider, you make it transaction data while it is actually master data...
    Edited by: J. W. ter Avest on Jan 13, 2011 1:11 PM

  • How to get this with Single query

    Friends
    I am sure using SQL analytical function, the following can be achieved using a single query:
    Date_value | Cust_id | Customer_tenue | avg_bal
    01-aug-09 | 111 | 0 | 1000
    01-aug-09 | 112 | 1 | 2000
    01-aug-09 | 113 | 2 | 900
    01-aug-09 | 114 | 3 | 1250
    01-sep-09 | 111 | 1 | 1200
    01-sep-09 | 112 | 2 | 2000
    01-sep-09 | 113 | 3 | 1900
    01-sep-09 | 114 | 4 | 1250
    01-oct-09 | 111 | 2 | 1100
    01-oct-09 | 112 | 3 | 2200
    01-oct-09 | 113 | 4 | 1900Expected result
    If customer’s tenure is 0 then mark as ‘New’,
    If customer’s balance is increased from last month then mark as ‘Augment’
    If customer’s balance is same as last month then mark as ‘Maintain’
    If customer’s balance is decreased from last month then mark as ‘Diminish’
    Else ‘Left’
    Help please....

    If customer’s tenure in last month is 0 then mark as ‘New’,There's not such case in test data... last month is October, isn't it?
    SQL> with t as (select DATE '2009-08-01' Date_value, 111 Cust_id, 0 Customer_tenue, 1000 avg_bal from dual union all
      2  select DATE '2009-08-01', 112 , 1 , 2000 from dual union all
      3  select DATE '2009-08-01', 113 , 2 , 900 from dual union all
      4  select DATE '2009-08-01', 114 , 3 , 1250 from dual union all
      5  select DATE '2009-09-01', 111 , 1 , 1200 from dual union all
      6  select DATE '2009-09-01', 112 , 2 , 2000 from dual union all
      7  select DATE '2009-09-01', 113 , 3 , 1900 from dual union all
      8  select DATE '2009-09-01', 114 , 4 , 1250 from dual union all
      9  select DATE '2009-10-01', 111 , 2 , 1100 from dual union all
    10  select DATE '2009-10-01', 112 , 3 , 2200 from dual union all
    11  select DATE '2009-10-01', 113 , 4 , 1900 from dual)
    12  select date_value, cust_id, avg_bal, oldbal, case when Customer_tenue=0 and nextbal is null then 'NEW'
    13                                                    when oldbal<avg_bal then 'Augment'
    14                                                    when oldbal=avg_bal then 'Maintain'
    15                                                    when oldbal>avg_bal then 'Diminish'
    16                                                    else 'Left' end status
    17    from (select date_value, cust_id, customer_tenue, avg_bal, LEAD(avg_bal) over (partition by cust_id order by date_value desc) oldbal,
    18                 LAG(avg_bal) over (partition by cust_id order by date_value desc) nextbal
    19            from t)
    20  order by cust_id, date_value;
    DATE_VALU    CUST_ID    AVG_BAL     OLDBAL STATUS
    01-AGO-09        111       1000            Left
    01-SET-09        111       1200       1000 Augment
    01-OTT-09        111       1100       1200 Diminish
    01-AGO-09        112       2000            Left
    01-SET-09        112       2000       2000 Maintain
    01-OTT-09        112       2200       2000 Augment
    01-AGO-09        113        900            Left
    01-SET-09        113       1900        900 Augment
    01-OTT-09        113       1900       1900 Maintain
    01-AGO-09        114       1250            Left
    01-SET-09        114       1250       1250 Maintain
    Selezionate 11 righe.Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

  • How to include 0STOCK_VAL in a Query based on APO DataSource?

    Hi All,
    I have a requirement to include *0STOCK_VAL" from Inventory to the APO InfoCube. But the problem with this is, this particular KeyFigure is not present in the APO hence it cannot be included in the APO DataSource i.e. we cannot get this from the Source System.
    I checked the Production system, 0STOCK_VAL InfoObject is avaiable in one of the InfoCube but it is not present in any DSO's. Since it is not present in any of the DSO's we cannot write a Routine to read it from any of the table.
    I even thought of including the InfoCube where 0STOCK_VAL is present into a MultiProvider along with the APO InfoCube. I can define the joining condition based on Plant and Material. But if I drill down any other characteristics which are not common in both the  InfoCube then we will have a blank line in the Query which is not recommended.
    But this KeyFigure is very much needed in the Query.
    My question is how to include this in the APO InfoCube or How to get this in the Query with values??
    Can anybody please help me on this.
    Thanks in advance.
    Prasapbi

    hi Matt,
      In your example like a transaction was paid for with a payment type of PTAM, then you need all the transaction details. I suppose that all the required transaction details along with payment type PTAM will be loaded into an infoprovider and you run a report on top of this infoprovider. Then for that report you need to have a selection screen variable for Payment Type and if the user enters the payment type PTAM, then he can get all the other transaction details from the infoprovider.
    Let me know if i don't understand the requirement correctly.
    Hope it helps....

  • How to use Key Date in query

    Imagine an invoice was created for a customer on the 1st of January 2008 for £1000
    On the 1st of Feb, he paid $300, owing $700
    On the 1st of Mar, he paid $450, owing $250
    On the 1st of Apr, he paid $250.
    If I run an AR report today the 10th of Aug, I would see he owes nothing. What I want to do is to run the report today based on the 2nd of March and see a debt of £250. I dont want to use the posting date in the selection criteria henceI think this is the case when you use a key date but I’m not sure how to use this in the query properties of BI7. What Characteristic do I need to specify as time dependant? Is there anything else I should consider?

    hi,
    Key Date setting is for the 'time dependent' master data.
    Lets say u have a Characteristic MATERIAL with a time dependent attribute MATERIAL GROUP as follows.
    MATERIAL FROM TO MATERIAL GROUP
    ABD 01/01/1995 12/31/2003 X
    ABD 01/01/2004 12/31/9999 Y
    Depending on what you have for the Keydate, the Material group is selected.
    If your key date is, ex, 06/12/2001 there material group is X. Or if key date is 02/15/2005, material group is Y.
    If you do not enter any value for keydate, system automatically assumes today' date.
    hope it helps..

  • How to tune this query

    Hi,
    Im trying to select the latest set of data from a table using a simple query for inserting into a new table.
    Details are given below.
    There are no indices for the table. Its taking around 18 sec.
    Pls advice on how to proceed so that I can bring down this time.
    Query:
    SELECT
    FROM
    M_UNDR M
    WHERE
    M.M_DATE = (SELECT MAX(M_DATE) FROM M_UNDR M1)
    AND
    M.M_TIME =
    SELECT MAX(M_TIME) FROM M_UNDR M2 WHERE M2.M_DATE = M.M_DATE
    AND
    M.U_TYPE NOT IN ('USD', 'GBP', 'EUR');
    SQL> select count(1) from m_undr;
      COUNT(1)
       2695446
    SQL>
    Version:
    SQL> select banner from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for Solaris: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Explain plan
    PLAN_TABLE_OUTPUT
    | Id  | Operation            | Name           | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |                |     1 |    95 | 19060 |
    |   1 |  HASH JOIN           |                |     1 |    95 | 12882 |
    |   2 |   VIEW               | VW_SQ_1        |   508 | 11176 |  6608 |
    |   3 |    HASH GROUP BY     |                |   508 | 10668 |  6608 |
    |   4 |     TABLE ACCESS FULL| M_UNDR |  2392K|    47M|  6186 |
    |   5 |   TABLE ACCESS FULL  | M_UNDR |  5594 |   398K|  6274 |
    |   6 |    SORT AGGREGATE    |                |     1 |     8 |       |
    |   7 |     TABLE ACCESS FULL| M_UNDR |  2392K|    18M|  6178 |
    SQL> sho parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.3
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     200
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    SQL> sho parameter DB_FILE_MULTI
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     16
    SQL> show parameter db_block_size
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    SQL> show parameter cursor_sharing
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    Trace:
    SQL> set autotrace traceonly arraysize 100
    SQL> SELECT
      2  *
      3  FROM
      4  M_UNDR M
      5  WHERE
      6  M.M_DATE = (SELECT MAX(M_DATE) FROM M_UNDR M1)
      7  AND
      8  M.M_TIME =
      9  (
    10  SELECT MAX(M_TIME) FROM M_UNDR M2 WHERE M2.M_DATE = M.M_DATE
    11  )
    12  AND
    13  M.U_TYPE NOT IN ('USD', 'GBP', 'EUR');
    239 rows selected.
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=19060 Card=1 Bytes
              =95)
       1    0   HASH JOIN (Cost=12882 Card=1 Bytes=95)
       2    1     VIEW OF 'VW_SQ_1' (VIEW) (Cost=6608 Card=508 Bytes=11176
       3    2       HASH (GROUP BY) (Cost=6608 Card=508 Bytes=10668)
       4    3         TABLE ACCESS (FULL) OF 'M_UNDR' (TABLE) (Cos
              t=6186 Card=2392724 Bytes=50247204)
       5    1     TABLE ACCESS (FULL) OF 'M_UNDR' (TABLE) (Cost=62
              74 Card=5594 Bytes=408362)
       6    5       SORT (AGGREGATE)
       7    6         TABLE ACCESS (FULL) OF 'M_UNDR' (TABLE) (Cos
              t=6178 Card=2392724 Bytes=19141792)
    Statistics
              1  recursive calls
              0  db block gets
          91479  consistent gets
           4830  physical reads
              0  redo size
          15457  bytes sent via SQL*Net to client
            359  bytes received via SQL*Net from client
              4  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            239  rows processed
    SQL> disconnect
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  0br4mzjgj63dw, child number 0
    SELECT /*+ gather_plan_statistics */ * FROM M_UNDR M WHERE M.M_DATE = (SELECT MAX(M_DATE) FROM
    M_UNDR M1) AND M.M_TIME = ( SELECT MAX(M_TIME) FROM M_UNDR M2 WHERE M2.M_DATE = M.M_DATE )
    AND M.U_TYPE NOT IN ('USD', 'GBP', 'EUR')
    Plan hash value: 1220141218
    | Id  | Operation            | Name           | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |*  1 |  HASH JOIN           |                |      1 |      1 |    239 |00:00:06.94 |   91479 |  1114K|  1114K| 1209K (0)|
    |   2 |   VIEW               | VW_SQ_1        |      1 |    508 |    607 |00:00:04.06 |   30492 |    |  |          |
    |   3 |    HASH GROUP BY     |                |      1 |    508 |    607 |00:00:04.06 |   30492 |    |  |          |
    |   4 |     TABLE ACCESS FULL| M_UNDR |      1 |   2392K|   2695K|00:00:00.01 |   30492 |    |  |          |
    |*  5 |   TABLE ACCESS FULL  | M_UNDR |      1 |   5594 |   5497 |00:00:02.81 |   60987 |    |  |          |
    |   6 |    SORT AGGREGATE    |                |      1 |      1 |      1 |00:00:01.20 |   30492 |    |  |          |
    |   7 |     TABLE ACCESS FULL| M_UNDR |      1 |   2392K|   2695K|00:00:00.01 |   30492 |    |  |          |
    Predicate Information (identified by operation id):
       1 - access("M"."M_TIME"="VW_COL_1" AND "M_DATE"="M"."M_DATE")
       5 - filter(("M"."U_TYPE"<>'USD' AND "M"."U_TYPE"<>'GBP' AND "M"."U_TYPE"<>'EUR' AND "M"."M_DATE"=))
    26 rows selected.I have tried using rank as below. Didnt find any improvement.
    select * from
    SELECT
    m.*,
    rank() over (order by m_date desc, m_time desc) rnk
    FROM
    M_UNDR M
    WHERE
    M.U_TYPE NOT IN ('USD', 'GBP', 'EUR')
    where rnk  = 1Thanks in advance

    Hi,
    creating index on m_date and m_time did have gr8 impact on the plan.
    Query is completing in 2 sec now.
    Id  | Operation                      | Name               | Rows  | Bytes | Cost  |
       0 | SELECT STATEMENT               |                    |     1 |    73 |  6234 |
       1 |  TABLE ACCESS BY INDEX ROWID   | M_UNDR     |     2 |   146 |    51 |
       2 |   INDEX RANGE SCAN             | IND_M_UNDR |     2 |       |    49 |
       3 |    SORT AGGREGATE              |                    |     1 |    13 |       |
       4 |     FIRST ROW                  |                    |  5683 | 73879 |     6 |
       5 |      INDEX RANGE SCAN (MIN/MAX)| IND_M_UNDR |  5683 | 73879 |     6 |
       6 |    SORT AGGREGATE              |                    |     1 |     8 |       |
       7 |     INDEX FULL SCAN (MIN/MAX)  | IND_M_UNDR |  2392K|    18M|       |
    ------------------------------------------------------------------------------------Thanks for the help. Will check if there is any serious impact on insert.

  • How to use this query in R12

    the query below , i am using in valueset :
    select * from AR_LOCATION_VALUES
    Where ar_location_values.location_segment_qualifier =
    'COUNTRY' and ar_location_values.location_structure_id in ( select location_structure_id from ar_system_parameters )
    how to use this query to set in R12?
    Thanks

    hi
    i am using the following query in 11i and i want to use the same in R12 :
    SELECT ar_location_values.location_segment_description,ar_location_values.location_segment_value,location_segment_id
    FROM AR_LOCATION_VALUES
    WHERE ar_location_values.location_segment_qualifier = 'COUNTRY'
    AND ar_location_values.location_structure_id IN
    (SELECT location_structure_id FROM ar_system_parameters)
    note: the table ar_location_values is obsolette in R12 so what is the replacement table in R12 for this?

Maybe you are looking for

  • Windows 7 x64, MacBook Pro, frequent CHKDSK after HDD firmware update

    Hello, I have been having filesystem problems on my Windows 7 partition since the HDD related firmware update (the latest Performance update) was released and installed onto this mid 2009 MacBook Pro. The HDD is a 500 GB 7200 RPM model, but it never

  • Can I have 2 displays hooked up to my macbook pro via usb and display port

    I have a Macbok Pro (15 inch 2011) can I hook a monitor via USB (mirrored) and hook a second one via displayport to dvi as extendd, its because i want 2 bigger monitors on my desk, thank you all info appreciated

  • ABS does not download the entire package tree

    I want to compile php-apache in order to work with apache24 from the AUR but when I run abs it does not download the source code of the php-apache package. That's the case with many packages as well. After updating pacman database and running abs: ls

  • Error sending e-mail.

    Hi, Since last 2 years this code was working perfectly and suddenly since last 2 days, this code is giving error, would you guys help me here. Please find below the ERROR CODE: E-mail couldn't be sent. Error returned: Failed to connect to mail.mudhra

  • Write arrays to file

    Hi, I want to write some arrays into a file side by side. Like that.. A B C D 1 0,25 0,4 0,25 2 0,36 0,3 0,96 Hox can i do it? Thanks a lot.. irfan