MAX Function Not Giving Accurate Results

Hello,
I have the following sql
select ename ,temp,max(ver) as rv from
table
WHERE id = 5000
AND id2 = 8000
group by ename ,tempProblem with the above is always gives two records, ideally it should give only one which should be max(ver).
How can I resolve this issue?
Regards

I'm not sure whether you are looking this or not?
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.02
satyaki>
satyaki>
satyaki>with tt
  2  as
  3    (
  4      select 'THOMAS' ename, 'HR-022' temp, 2 ver from dual
  5      union all
  6      select 'EDWARD', 'FIN-011', 1 from dual
  7      union all
  8      select 'JOHN', 'IT-055', 3 from dual
  9      union all
10      select 'JOHN', 'IT-055', 1 from dual
11      union all
12      select 'JOHN', 'IT-055', 2 from dual
13    )
14  select k.ename,
15         k.temp,
16         k.ver
17  from (
18          select m.*,
19                 max(ver) over(partition by m.ename,m.temp order by m.ename,m.temp) rn
20          from tt m
21       ) k
22  where k.ver = k.rn;
ENAME  TEMP           VER
EDWARD FIN-011          1
JOHN   IT-055           3
THOMAS HR-022           2
Elapsed: 00:00:00.00
satyaki>
satyaki>Regards.
Satyaki De.

Similar Messages

  • MAX Function not returning MAX

    I have a query that is pulling in EDI 214 status codes, and want to pull in the last received status for status type "AG". To do this, I'm using the MAX function on the INSERT_DATE field of the status code AG, but the query keeps returning both AG status codes. I've tried this in a single query (Query 1) but it did not work so I also attempted it in a much smaller query to be used as a subquery, but that still did not work. Can anyone identify what the issue is with what I'm attempting to do?
    Query 1 (All Inclusive):
    SELECT BS.SHIPMENT_GID AS BUY_SHIPMENT_GID,
    AGSS.EVENTDATE AS AG_EVENT,
    D1SS.EVENTDATE AS D1_EVENT,
    BS.START_TIME AS BUY_START_TIME,
    AGSS.STATUS_CODE_GID AS AG,
    D1SS.STATUS_CODE_GID AS D1,
    BS.DOMAIN_NAME AS BUY_DOMAIN,
    MAX(AGSS.INSERT_DATE) AS AG_INSERT_DATE,
    MAX(D1SS.INSERT_DATE) AS D1_INSERT_DATE,
    BS.START_TIME,
    BS.DOMAIN_NAME,
    SHIPSTAT.STATUS_VALUE_GID
    FROM V_ROD_SHIPMENT BS
    INNER JOIN V_ROD_SS_STATUS_HISTORY AGSH
    ON (BS.SHIPMENT_GID = AGSH.SHIPMENT_GID)
    INNER JOIN V_ROD_IE_SHIPMENTSTATUS AGSS
    ON (AGSH.I_TRANSACTION_NO = AGSS.I_TRANSACTION_NO)
    INNER JOIN V_ROD_SS_STATUS_HISTORY D1SH
    ON (BS.SHIPMENT_GID = D1SH.SHIPMENT_GID)
    INNER JOIN V_ROD_SHIPMENT_STATUS SHIPSTAT
    ON (BS.SHIPMENT_GID = SHIPSTAT.SHIPMENT_GID)
    INNER JOIN V_ROD_IE_SHIPMENTSTATUS D1SS
    ON D1SH.I_TRANSACTION_NO = D1SS.I_TRANSACTION_NO
    WHERE BS.START_TIME > '18/MAY/12'
    AND BS.DOMAIN_NAME = 'UPS/CP/HDMB'
    AND AGSS.STATUS_CODE_GID = 'AG'
    AND D1SS.STATUS_CODE_GID = 'D1'
    AND (SHIPSTAT.STATUS_VALUE_GID = BS.DOMAIN_NAME
    || '.SECURE RESOURCES_ACCEPTED'
    OR SHIPSTAT.STATUS_VALUE_GID = BS.DOMAIN_NAME
    || '.SECURE RESOURCES_PICKUP NOTIFICATION')
    GROUP BY BS.SHIPMENT_GID,
    AGSS.EVENTDATE,
    D1SS.EVENTDATE,
    BS.START_TIME,
    AGSS.STATUS_CODE_GID,
    D1SS.STATUS_CODE_GID,
    BS.DOMAIN_NAME,
    SHIPSTAT.STATUS_VALUE_GID
    Query 2 (to be used as a sub-query if I cannot pull MAX insert date in previous query):
    SELECT DISTINCT BS.SHIPMENT_GID AS BUY_SHIPMENT_GID,
    AGSS.EVENTDATE AS AG_EVENT,
    AGSS.STATUS_CODE_GID AS AG,
    MAX(AGSS.INSERT_DATE) AS AG_INSERT_DATE
    FROM V_ROD_SHIPMENT BS
    INNER JOIN V_ROD_SS_STATUS_HISTORY AGSH
    ON (BS.SHIPMENT_GID = AGSH.SHIPMENT_GID)
    INNER JOIN V_ROD_IE_SHIPMENTSTATUS AGSS
    ON (AGSH.I_TRANSACTION_NO = AGSS.I_TRANSACTION_NO)
    WHERE AGSS.STATUS_CODE_GID = 'AG'
    AND BS.SHIPMENT_GID = 'UPS/CP/HDMB.HDM-1000203768'
    GROUP BY BS.SHIPMENT_GID,
    AGSS.EVENTDATE,
    AGSS.STATUS_CODE_GID
    Results of query 2 (similar issue as query 1, query doesn't return MAX insert date):
    BUY_SHIPMENT_GID     AG_EVENT     AG     AG_INSERT_DATE
    UPS/CP/HDMB.HDM-1000203768     5/25/2012 6:00:00 PM     AG     5/21/2012 3:10:36 PM
    UPS/CP/HDMB.HDM-1000203768     6/1/2012 5:00:00 PM     AG     5/20/2012 2:36:18 PM
    I appreciate any help.
    Thanks,
    -Adam

    Hi, Adam,
    Welcome to the forum!
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    If you can show what the problem is using commonly available tables (such as those in the scott schem) then you don't have to psot any sample data; just the results and the explanation.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}
    MAX (insert_date) returns the latest insert_date. I think, in this problem, you don't really want the latest insert_date; you want the status code that's related to the last insert_date. One way to get that is the aggregate FIRST (or LAST) function.
    Consider this query, using the scott.emp table:
    SELECT       ename
    ,       hiredate
    FROM       scott.emp
    ORDER BY  hiredate
    ,            ename
    ;Output:
    ENAME      HIREDATE
    SMITH      17-Dec-1980
    ALLEN      20-Feb-1981
    WARD       22-Feb-1981
    JONES      02-Apr-1981
    BLAKE      01-May-1981
    CLARK      09-Jun-1981
    TURNER     08-Sep-1981
    MARTIN     28-Sep-1981
    KING       17-Nov-1981
    FORD       03-Dec-1981
    JAMES      03-Dec-1981
    MILLER     23-Jan-1982
    SCOTT      19-Apr-1987
    ADAMS      23-May-1987Say we're only interested in seeing the last hiredate, and the name of the person hired on that date:
    LAST_ENAME LAST_HIREDA
    ADAMS      23-May-1987Here's how to get those results using the aggregate LAST function:
    SELECT       MIN (ename) KEEP (DENSE_RANK LAST ORDER BY hiredate) AS last_ename
    ,       MAX (hiredate)                                              AS last_hiredate
    FROM       scott.emp
    ;What if there's a tie for the latest hiredate? For example, say we're only looking at people hired before 1982. In that case, the latest hiredate is December 3, 1981, and there happen to be two people hired on that date. This query
    SELECT       MIN (ename) KEEP (DENSE_RANK LAST ORDER BY hiredate) AS last_ename
    ,       MAX (hiredate)                                              AS last_hiredate
    FROM       scott.emp
    WHERE         hiredate     < DATE '1982-01-01'
    ;produces only 1 row of output:
    LAST_ENAME LAST_HIREDA
    FORD       03-Dec-1981Why did it show FORD rather than JAMES? Because of the MIN function. When there happens to be a tie for the latest hiredate, MIN says to return the first ename (in normal sort order) of the rows that have that hiredate.
    FIRST and LAST work with GROUP BY, too.
    In the example above, we were only looking at one column related to the latest hiredate. If we neede to see several columns, it would be simpler to use the analytic ROW_NUMBER function:
    WITH     got_r_num     AS
         SELECT  emp.*
         ,     ROW_NUMBER () OVER ( ORDER BY  hiredate  DESC
                                   ,            ename
                           ) AS r_num
         FROM    scott.emp
         WHERE     hiredate     < DATE '1982-01-01'
    SELECT     *
    FROM     got_r_num
    WHERE     r_num     = 1
    I hope this answers your question.
    If not, post a more complete explanation of what you want to do. if you have to use your own tables, then post CREATE TABLE and INSERT statements for a little sample data. Post the results you want from that data, and explain how you get those results from that data.

  • Table-Valued Function not returning any results

    ALTER FUNCTION [dbo].[fGetVendorInfo]
    @VendorAddr char(30),
    @RemitAddr char(100),
    @PmntAddr char(100)
    RETURNS
    @VendorInfo TABLE
    vengroup char(25),
    vendnum char(9),
    remit char(10),
    payment char(10)
    AS
    BEGIN
    insert into @VendorInfo (vengroup,vendnum)
    select ks183, ks178
    from hsi.keysetdata115
    where ks184 like ltrim(@VendorAddr) + '%'
    update @VendorInfo
    set remit = r.remit
    from
    @VendorInfo ven
    INNER JOIN
    (Select ksd.ks188 as remit, ksd.ks183 as vengroup, ksd.ks178 as vendnum
    from hsi.keysetdata117 ksd
    inner join @VendorInfo ven
    on ven.vengroup = ksd.ks183 and ven.vendnum = ksd.ks178
    where ksd.ks192 like ltrim(@RemitAddr) + '%'
    and ks189 = 'R') r
    on ven.vengroup = r.vengroup and ven.vendnum = r.vendnum
    update @VendorInfo
    set payment = p.payment
    from
    @VendorInfo ven
    INNER JOIN
    (Select ksd.ks188 as payment, ksd.ks183 as vengroup, ksd.ks178 as vendnum
    from hsi.keysetdata117 ksd
    inner join @VendorInfo ven
    on ven.vengroup = ksd.ks183 and ven.vendnum = ksd.ks178
    where ksd.ks192 like ltrim(@PmntAddr) + '%'
    and ks189 = 'P') p
    on ven.vengroup = p.vengroup and ven.vendnum = p.vendnum
    RETURN
    END
    GO
    Hi all,
    I'm having an issue where my Table-Valued Function is not returning any results.
    When I break it out into a select statement (creating a table, and replacing the passed in parameters with the actual values) it works fine, but with passing in the same exact values (copy and pasted them) it just retuns an empty table.
    The odd thing is I could have SWORN this worked on Friday, but not 100% sure.
    The attached code is my function.
    Here is how I'm calling it:
    SELECT * from dbo.fGetVendorInfo('AUDIO DIGEST', '123 SESAME ST', 'TOP OF OAK MOUNTAIN')
    I tried removing the "+ '%'" and passing it in, but it doesn't work.
    Like I said if I break it out and run it as T-SQL, it works just fine.
    Any assistance would be appreciated.

    Why did you use a proprietary user function instead of a VIEW?  I know the answer is that your mindset does not use sets. You want procedural code. In fact, I see you use an “f-” prefix to mimic the old FORTRAN II convention for in-line functions! 
    Did you know that the old Sybase UPDATE.. FROM.. syntax does not work? It gives the wrong answers! Google it. 
    Your data element names make no sense. What is “KSD.ks188”?? Well, it is a “payment_<something>”, “KSD.ks183” is “vendor_group” and “KSD.ks178” is “vendor_nbr” in your magical world where names mean different things from table to table! 
    An SQL programmer might have a VIEW with the information, something like:
    CREATE VIEW Vendor_Addresses
    AS
    SELECT vendor_group, vendor_nbr, vendor_addr, remit_addr, pmnt_addr
      FROM ..
     WHERE ..;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • SPEL not giving desired result

    Hi ALL,
    SPEL
    *${oa.TestPVO1.xxDisable}* on Disable Property for a button
    In CO
    OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
    am.invokeMethod("hide");
    In AM
    public void hide()
    OAViewObject disvo = (OAViewObject)getTestPVO1();
    if (!disvo.isPreparedForExecution())
    disvo.executeQuery();
    Row drow = disvo.createRow();//.getCurrentRow();
    disvo.insertRow(drow);
    drow.setAttribute("xxDisable", Boolean.FALSE);
    NOT giving desired o/p to disable the button
    Thanks,
    Sombit.
    Edited by: Sombit on Oct 1, 2009 7:33 AM

    Try assigning the SPEL value in the *VORowImpl.
    First, in order to assign a value to SPEL, you'll need to create a custom VO. Here's a sample query I've used to create my VO to pull data pertainining to if an Attribute should be mandatory/rendered.
    SELECT min(descriptive_flex_context_code) descriptive_flex_context_code, min(Enabled) Enabled, min(END_USER_COLUMN_NAME) END_USER_COLUMN_NAME, min(required_flag) required_flag, min(application_column_name) application_column_name,
    min(xxx.LOV) LOV
    from
    (SELECT descriptive_flex_context_code,'Y' Enabled, END_USER_COLUMN_NAME, required_flag, application_column_name,
    decode(ffvv.flex_value,null,'N','Y') LOV
    FROM FND_DESCR_FLEX_COL_USAGE_VL fdfc,
    fnd_flex_values_vl ffvv
    WHERE (fdfc.APPLICATION_ID=20045)
    and (fdfc.DESCRIPTIVE_FLEXFIELD_NAME LIKE 'SPL Account Map')
    and fdfc.enabled_flag = 'Y'
    and fdfc.display_flag = 'Y'
    and fdfc.application_column_name = 'ATTRIBUTE5'
    and ffvv.flex_value_set_id(+) = fdfc.flex_value_set_id
    and rownum = 1) xxx
    Once the VO is created, I created several transient "boolean" attributes in my VO. These attributes will be assigned a value based on code I place in my *VORowImpl since this is the file which controls attribute assignments.
    But before that, in my *VOImpl, I've defined a custom method which is used to execute the VO from my AM.
    public class Ref5PVOImpl extends OAViewObjectImpl
    * This is the default constructor (do not remove)
    public Ref5PVOImpl()
    public void initRef5PVO()
    // setWhereClause("descriptive_flex_context_code in (select vendor_name from spl_account_map where cont_cd = :1)");
    setWhereClauseParams(null); //Always reset
    // setWhereClauseParam(0, acct);
    // System.out.println("value_selected customer>> "+acct);
    executeQuery();
    In my *VORowImpl, I've added custom code to my Attribute methods so that they return the proper values when invoked...
    public String getMakeRequired()
    if (getRequiredFlag()!= null)
    if ("Y".equals(getRequiredFlag()))
    //if(getMessageChoiceAttribute()==null)
    System.out.println("Required returned yes");
    return "yes";
    else
    System.out.println("Required returned no");
    return "no";
    else
    return "no"; //poplist will be disabled - DFF is not configured
    public Boolean getOptionRender()
    if (getLov()!= null)
    // In this method check if the Message Text Input is valid
    if ("N".equals(getLov()))
    System.out.println("OptionRender returned true "+ getLov());
    return Boolean.TRUE; //text input will be enabled if no LOV exists
    else
    System.out.println("OptionRender returned false "+ getLov());
    return Boolean.FALSE; //text input will be disabled if LOV exists
    else
    return Boolean.FALSE; //text input will be disabled - DFF is not configured
    Then add your SPEL directive into your field's Property inpector...
    ${oa.Ref5PVO1.MakeRequired}
    ${oa.Ref5PVO1.OptionRender}

  • Goto link query is not giving exact results

    Hi Folks
    I am having issue with GOTO query.
    My main query gives details of Employee seperation in particular year.
    For this query i have goto query.
    When i am checking the details of goto query ,it is giving incorrect results.
    Your help is appreciated.
    Thanks & Regards,
    Hari Reddy

    Hi Hari,
        Check in RSBBS, whether you specified the receiver query correctly...
    Check the link:
    [http://help.sap.com/saphelp_nw04/helpdata/en/99/08629bd3e41d418530c6849df303c9/content.htm]
        Hope this helps you.
    Regards,
    Yokesh.

  • The Same Excel Functions Not Giving the Same Result in Numbers

    I'm been using Excel for years and now that I've made the switch to Mac, I thought I should probably utilise the iWork suite of software and get rid of Microsoft once and for all.
    Whilst I love the user-friendliness, there are so many small things that Apple to appear to have overlooked which keeps me hanging on to Microsoft Office just a little, but I digress.
    OK, So I have one sheet in Numbers with the following data.
    I am trying I need to search Column A for the TLDs in Column C, if they exist output the correct renewal price from Column D in Column B
    e.g. A2 contains .net so  B2 should have 12.50 in it.
    A
    B
    C
    D
    1
    Domain Name
    Renewal Price 1
    TLDs
    Renewal Price 2    
    2
    test.net
    .com
    5.00
    3
    test.co.uk
    .co.uk
    10.00
    4
    test.com
    .net
    12.50
    So... can someone please explain to me why the same functions which exist in Numbers and Excel (VLOOKUP / LOOKUP / SEARCH) do not work in Numbers as they do in Excel? If there is a valid reason, fine, I'll accept that, but how do I acheive the above?
    The formula which WORKS in B2 in Excel but NOT in Numbers is:
    =VLOOKUP(LOOKUP(32768,SEARCH(C$2:C$4,A2),C$2:C$4),$C$2:$E$4,2,FALSE)
    Thanks in advance.

    So... can someone please explain to me why the same functions which exist in Numbers and Excel (VLOOKUP / LOOKUP / SEARCH) do not work in Numbers as they do in Excel? If there is a valid reason, fine, I'll accept that, but how do I acheive the above?
    That's a form of "array function" (searching a "table array").  Numbers can't do array functions the way Excel can.
    Here's one way to achieve the same goal in Numbers:
    The formula in B2, copied down:
         =VLOOKUP(RIGHT(A2,LEN(A2)−SEARCH(".",A2)+1),Prices::$A:$B,2,FALSE)
    SG

  • % Change is not giving correct results.

    Hi,
    I am using Ago Function to calculate Current month cx count , previous month cx count, present month acct count, previous month acct count and in the report parameter selecting Reporting Month as DEC 09. The results are coming perfectly fine... but when I create % Change Previous Month Cx count and % change Previous month Account count, It is not showing the correct results and getting only 0% listed even if the Difference is huge and should be around 10% ...
    The code written to calculate % change is :
    CASE WHEN ("EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count" IS NULL OR "EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count" = 0) AND NOT "EIP BDW Analytics"."EIP Reporting FACT"."Current Month Account Count" IS NULL AND "EIP BDW Analytics"."EIP Reporting FACT"."Current Month Account Count" <> 0 THEN 100.0 WHEN ("EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count" IS NULL OR "EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count" = 0) AND ("EIP BDW Analytics"."EIP Reporting FACT"."Current Month Account Count" IS NULL OR "EIP BDW Analytics"."EIP Reporting FACT"."Current Month Account Count" = 0) THEN 0.0 WHEN "EIP BDW Analytics"."EIP Reporting FACT"."Current Month Account Count" IS NULL AND NOT "EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count" IS NULL AND "EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count" <> 0 THEN -(100.0) ELSE 100.0 * ("EIP BDW Analytics"."EIP Reporting FACT"."Current Month Account Count" - "EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count") / "EIP BDW Analytics"."EIP Reporting FACT"."Previous Month Account Count" END
    Can some one tell me what I need to do in order to get the desired results.
    I am using a time dimension with the following hierarchy ( Year - Month - Period_ID) joined with the Reporting Table Fact which has count of cx and Count of Accts.

    We have two assets one acquired on 01/04/2014 and another on 26/04/2014.  Everything else is same for both assets like asset class , keys etc.
    Now here are two calculations.
    System is giving calculation ok , what should we do so that for both assets we are left with same scrap value (1047)  (and not 1119.68 as in last line )
    Can anyone help how to get value in last field of screen shot given below asset vale date or it is always blank.
    wanted to add something in our case DEP to the DAY is also ticked in dep key.
    regards
    Sanjeev Mehndiratta

  • Group by Query not giving desired results

    Hi,
    I've a requirement to find minimum month based on status:
    The following query is giving error :
    SELECT
              b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
              MIN(a.period_name)
    FROM     table a,
         table b
    WHERE     a.app_id     =     b.app_id
    AND          b.app_name      =     'NAME1'
    AND          a.book_id     =     &book_id
    AND          a.status      =      'O'
    GROUP BY      b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
    for ex: in the above query if I've four records with status 'O' and period_name as 'May-12', 'Jun-12','Jul-12' ,'Aug-12' then I need to pick 'May'
    Thanks,
    Kiran

    Hi, Kiran,
    user518071 wrote:
    Hi,
    I've a requirement to find minimum month based on status:
    The following query is giving error :
    SELECT
              b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
              MIN(a.period_name)
    FROM     table a,
         table b
    WHERE     a.app_id     =     b.app_id
    AND          b.app_name      =     'NAME1'
    AND          a.book_id     =     &book_id
    AND          a.status      =      'O'
    GROUP BY      b.app_name,
              DECODE (a.status,
              'C','Closed',
              'O','Open',
              'F','Future',
              'W','Pending',
              'N','Not Opened') decode_status
    for ex: in the above query if I've four records with status 'O' and period_name as 'May-12', 'Jun-12','Jul-12' ,'Aug-12' then I need to pick 'May'
    Thanks,
    KiranIt looks like you're almost there.
    If period_name is a DATE, then
    MIN (a.period_name)is finidng the earliest period name, such as 5 May 2012 17:03:49. If you just want to see 'May 2012', then change that to
    TO_CHAR ( MIN (a.period_name)
            , 'Mon YYYY'
            )If a.period_name is a VARCHAR2, then change it to a DATE. The best way to do this is permanently. There is no reason to store date information in VARCHAR2 columns. Oracle supplies DATE columns; there's no extra cost for using them. DATE columns were designed for storing date information, use them to do that.
    if you must keep your date information in VARCHAR2 a column, then use TO_DATE in the query. It will be slow, and you'll have run-time errors if any of the information is in the wrong format. That's what happens when you store date information in VARCHAR2 columns.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Outer Join not giving correct result

    I have two tables=> tab_child_tmp (product_id,region,child_val,mst_product) and
    tab_master_tmp (master_product_id,region,master_val)
    tab_child_tmp.mst_product is the foreign key referencing tab_master_tmp.master_product_id.
    Currently the tables are populated with below values
    tab_child_tmp
    PRODUCT_ID REGION CHILD_VAL MST_PRODUCT
    Arm-01,     CAL,     100,     Arm-Master
    Arm-01,     DEL,     222,     Arm-Master
    Arm-01,     CHEN,     55,     Arm-Master
    Arm-02,     MUM,     69,     Arm-Master
    Arm-02,     DEL,     90,     Arm-Master
    tab_master_tmp
    MST_PRODUCT     REGION     MASTER_VAL
    Arm-Master     , CAL,     390
    Arm-Master     , DEL,     300
    Arm-Master, CHEN,     450
    Arm-Master, MUM,     600
    Now I want to display the result in the below format
    PRODUCT_ID REGION CHILD_VAL MASTER_VAL
    1. Arm-01     , CAL, 100,     390
    2. Arm-01     , DEL, 222,     300
    3. Arm-01     , CHEN, 55,     450
    4. Arm-01     , MUM, 0,     600
    5. Arm-02     , MUM, 69,     600
    6. Arm-02     , DEL, 90,     300
    7. Arm-02     , CHEN, 0,     450
    8. Arm-02     , CAL, 0,     390
    When I am running the below query it is not returning the above 4,7 and 8 rows. Can you please provide the correct sql to get the above desired output
    SELECT
    a.product_id,
    nvl(a.region,b.region) geo,
    nvl(a.child_val,0)match_val,
    b.master_val
    FROM
    tab_child_tmp a,
    tab_master_tmp b
    WHERE
    a.mst_product(+) = b.master_product AND
    a.region(+) = b.region
    Thanks

    Hi
    Thanks for the reply. Please find below the details.
    Oracle Version*
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for Solaris: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Create Table Script_
    create table TAB_CHILD_TMP
    PRODUCT_ID VARCHAR2(50),
    REGION VARCHAR2(100),
    CHILD_VAL NUMBER,
    MST_PRODUCT VARCHAR2(50)
    create table TAB_MASTER_TMP
    MST_PRODUCT VARCHAR2(50),
    REGION VARCHAR2(100),
    MASTER_VAL NUMBER
    Insert Script_
    INSERT INTO tab_child_tmp VALUES ('Arm-01','CAL',100,'Arm-Master');
    INSERT INTO tab_child_tmp VALUES ('Arm-01','DEL',222,'Arm-Master');
    INSERT INTO tab_child_tmp VALUES ('Arm-01','CHEN',55,'Arm-Master');
    INSERT INTO tab_child_tmp VALUES ('Arm-Master','MUM',69,'PLC1');
    INSERT INTO tab_child_tmp VALUES ('Arm-Master','DEL',90,'PLC1');
    INSERT INTO tab_master_tmp VALUES ('Arm-Master','CAL',390);
    INSERT INTO tab_master_tmp VALUES ('Arm-Master','DEL',300);
    INSERT INTO tab_master_tmp VALUES ('Arm-Master','CHEN',450);
    INSERT INTO tab_master_tmp VALUES ('Arm-Master','MUM',600);
    INSERT INTO tab_master_tmp VALUES ('PLC1','MUM',199);
    INSERT INTO tab_master_tmp VALUES ('PLC1','DEL',299);
    INSERT INTO tab_master_tmp VALUES ('PLC1','CHEN',399);
    Expected output logic*
    Need to display the product value for each region along with the value of master product for the corresponding product and region. If a product doesn't belong to a particular region, but the corresponding master product is, then that value also needs to be displayed for that product and region with child value as zero.
    ie. for product Arm-01 there is no record in tab_child_tmp for region "MUM", but it's master product 'Arm-Master' has a record for region 'MUM' in tab master_tmp table. So in ouput there will be a record for product 'Arm-01' and region-'MUM' with child value as 0 and master value as 600.
    Expected Output*
    PRODUCT_ID ~~~ REG ~~~ CHILD_VAL ~~~ MASTER_VAL
    Arm-01 ~~~ CAL ~~~ 100 ~~~ 390
    Arm-01 ~~~ DEL ~~~ 222 ~~~ 300
    Arm-01 ~~~ CHEN ~~~ 55 ~~~ 450
    Arm-01 ~~~ MUM ~~~ 0 ~~~ 600
    Arm-MASTER ~~~ MUM ~~~ 69 ~~~ 199
    Arm-MASTER ~~~ DEL ~~~ 90 ~~~ 299
    Arm-MASTER ~~~ CHEN ~~~ 0 ~~~ 399
    Please help

  • Access and JDBC not giving correct results

    I am running a Query on an access DB
    SELECT COUNT(*) FROM TABLE1 WHERE [First Name] LIKE '*Jamie*'
    is the SQL query that should be executed. I get 0 errors or warnings but I get a result back as 0
    res.next(); int max = res.getInt(1);
    The max is always returned as 0.
    When I do the SAME SQL query but
    SELECT COUNT(*) FROM TABLE1 WHERE [First Name] = 'Jamie'
    and with the above code, I get results
    I am confused... please help!

    why should you? sql doesn't read minds. it's an error only in your understanding. you passed a perfectly reasonable string the first time.
    %

  • N86 camera not giving good results

    I have recently purchased N86 with 8 MP camera, I have heard that it takes stunning pictures but the results are not upto the mark. Colors are faded, pics taken at night are often blur, my friend has a blackberry phone with 3 mp camera when compared blackberry pictures were better than my phone.
    May be I haven't set the camera properly please guide me how to set it properly currently I have following settings:
    Image Quality: 8MP
    Extended Digital Zoom: off
    Face Detection: off
    Screen mode: Automatic
    Flash: Automatic
    Sequence Mode: Single Shot

    Best to consult and expert !
    http://3lib.ukonline.co.uk/sshow/ss111.html
    http://www.allaboutsymbian.com/features/item/How_to_Take_better_photos_on_your_Nokia_Nseries_smartph...
    If I have helped at all, a click on the White Star is always appreciated :
    you can also help others by marking 'accept as solution' 

  • Account Query is taking longtime and not giving desired results

    Hi,
    I'm trying to run the following query to get code combination id for last six months with 1)no activity in gl_je_lines
    2) Sum of begin balance and PTD is zero
    Her's query :
    select
    cc.segment3 SEGMENT
    from apps.gl_code_combinations cc,
    apps.gl_balances bal,
    apps.fnd_flex_values_vl ffvl,
    apps.fnd_flex_value_sets ffvs,
    (select period_name
    from apps.gl_periods
    where period_set_name ='abc Calendar'
    and to_date(period_name,'Mon-YY') between add_months(sysdate,(6*-1)-1) and sysdate) p
    where cc.CODE_COMBINATION_ID = bal.CODE_COMBINATION_ID
    and ffvl.FLEX_VALUE = cc.segment3
    and ffvl.FLEX_VALUE_SET_ID = ffvs.flex_value_set_id
    and ffvs.flex_value_set_id = 2222222
    and bal.SET_OF_BOOKS_ID =555
    and cc.CHART_OF_ACCOUNTS_ID = 11111
    and bal.period_name = p.period_name
    and ffvl.ENABLED_FLAG = 'Y'
    and ffvl.END_DATE_ACTIVE is null
    and bal.TEMPLATE_ID IS NULL
    and bal.actual_flag='A'
    and bal.currency_code 'STAT'
    and ffvl.creation_date <= add_months(sysdate,(6*-1)-1)
    and cc.SEGMENT3 not in (
    select
    distinct gcc.SEGMENT3
    from apps.gl_je_lines l
    , apps.gl_code_Combinations gcc,
    (select period_name
    from apps.gl_periods
    where period_set_name ='abc Calendar'
    and end_date > add_months(last_day(sysdate),-1) and end_date <= last_day(sysdate)) lp
    where l.code_combination_id = gcc.code_combination_id
    and gcc.CHART_OF_ACCOUNTS_ID = 11111
    and l.period_name=lp.period_name
    and l.set_of_books_id = 555
    and l.status='P')
    group by cc.SEGMENT3
    HAVING sum(abs(nvl(bal.BEGIN_BALANCE_DR,0))-abs(nvl(bal.BEGIN_BALANCE_CR,0))+abs(nvl(bal.PERIOD_NET_DR,0))-abs(nvl(bal.PERIOD_NET_CR,0))) = 0--------------------------------------------------------------------------------
    Here's Explain Plan
    Operation Node Cost IO Cost CPU Cost Cardinality Object Name Options Object Type Optimizer
    SELECT STATEMENT 5155 5094 554583434 1 ALL_ROWS
    FILTER
    HASH (GROUP BY) 5155 5094 554583434 1 GROUP BY
    FILTER
    TABLE ACCESS (BY INDEX ROWID) 4 4 31301 1 GL_BALANCES BY INDEX ROWID TABLE ANALYZED
    NESTED LOOPS 18 18 427467 1
    MERGE JOIN (CARTESIAN) 14 14 396166 1 CARTESIAN
    TABLE ACCESS (BY INDEX ROWID) 4 4 49409 1 GL_CODE_COMBINATIONS BY INDEX ROWID TABLE ANALYZED
    NESTED LOOPS 8 8 82677 1
    NESTED LOOPS 4 4 33268 1
    NESTED LOOPS 4 4 31368 1
    INDEX (UNIQUE SCAN) 1 1 8171 1 FND_FLEX_VALUE_SETS_U1 UNIQUE SCAN INDEX (UNIQUE) ANALYZED
    TABLE ACCESS (BY INDEX ROWID) 3 3 23196 1 FND_FLEX_VALUES BY INDEX ROWID TABLE ANALYZED
    INDEX (RANGE SCAN) 2 2 15293 1 FND_FLEX_VALUES_N3 RANGE SCAN INDEX ANALYZED
    INDEX (UNIQUE SCAN) 0 0 1900 1 FND_FLEX_VALUES_TL_U1 UNIQUE SCAN INDEX (UNIQUE) ANALYZED
    INDEX (RANGE SCAN) 2 2 33113 4 GL_CODE_COMBINATIONS_N3 RANGE SCAN INDEX ANALYZED
    FILTER
    TABLE ACCESS (BY INDEX ROWID) 20 20 163416 1 GL_JE_LINES BY INDEX ROWID TABLE ANALYZED
    NESTED LOOPS 5136 5076 545022343 1
    MERGE JOIN (CARTESIAN) 5103 5043 544739760 4 CARTESIAN
    TABLE ACCESS (BY INDEX ROWID) 5 5 37587 1 GL_PERIODS BY INDEX ROWID TABLE ANALYZED
    INDEX (RANGE SCAN) 2 2 15043 4 GL_PERIODS_N2 RANGE SCAN INDEX ANALYZED
    BUFFER (SORT) 5098 5038 544702173 7 SORT
    TABLE ACCESS (FULL) 5098 5038 544702173 7 GL_CODE_COMBINATIONS FULL TABLE ANALYZED
    INDEX (RANGE SCAN) 3 3 29414 36 GL_JE_LINES_N1 RANGE SCAN INDEX ANALYZED
    BUFFER (SORT) 10 10 346757 1 SORT
    INDEX (FULL SCAN) 6 6 313489 1 GL_PERIODS_U1 FULL SCAN INDEX (UNIQUE) ANALYZED
    INDEX (RANGE SCAN) 2 2 15493 1 GL_BALANCES_N1 RANGE SCAN INDEX ANALYZEDThis query is taking two hrs to get results :
    How to tune this query to get results faster

    Hi,
    170 posts and still do not know how to use {noformat}{noformat} tags?
    Please read <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360002">How do I ask a question on the forums?</a>
    If you have a performance issue have a look at <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360003">How to improve the performance of my query? / My query is running slow. </a>
    Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    Also consider closing some of your questions when someone is answering. Looking at your profile:
    Handle:      user518071 
    Status Level:      Newbie
    Registered:      Jun 30, 2006
    Total Posts:      170
    Total Questions:      92 (58 unresolved) it still looks that you have 58 unresolved questions. Are they really all unresolved?
    Regards.
    Al

  • MIX sale return problem(query not giving required result)

    i have written following query which is running sucessfully.the concept behind this query is to get a exact quantity of sold items after subtracting the sale return from the sale.now the problem is that when user take sale return against invoice then this query providing ok result but when user take sale return against MIX items not knowing exactly the invoice then query is not showing result means not subtracting MIX sale from sale.please help me to get required result from this query.
    i m using oracle 9i with developer 6i
    select s.price,s.item_code,S.DESCR,
    sum(decode(d.MONno,01,NVL(S.QTY,0),0)) JAN,
    sum(decode(d.MONno,02,NVL(S.QTY,0),0)) FEB,
    sum(decode(d.MONno,03,NVL(S.QTY,0),0)) MAR,
    sum(decode(d.MONno,04,NVL(S.QTY,0),0)) APR,
    sum(decode(d.MONno,05,NVL(S.QTY,0),0)) MAY,
    sum(decode(d.MONno,06,NVL(S.QTY,0),0)) JUN,
    sum(decode(d.MONno,07,NVL(S.QTY,0),0)) JULY,
    sum(decode(d.MONno,08,NVL(S.QTY,0),0)) AUG,
    sum(decode(d.MONno,09,NVL(S.QTY,0),0)) SEP,
    sum(decode(d.MONno,10,NVL(S.QTY,0),0)) OCT,
    sum(decode(d.MONno,11,NVL(S.QTY,0),0)) NOV,
    sum(decode(d.MONno,12,NVL(S.QTY,0),0)) DEC,
    sum(S.qty) TU
    FROM
    (select nvl(sales_detail.qty,0)+NVL(sales_detail.bonus,0) as qty,
    sales_detail.item_code AS ITEM_CODE,stock_reg.price price,
    stock_reg.descr AS descr,
    s_date as sale_date FROM
    SALES_DETAIL,SALES_HEADER,STOCK_REG
    WHERE SALES_DETAIL.S_ID = SALES_HEADER.S_ID AND
    SALES_DETAIL.STOCKCODE = STOCK_REG.STOCKCODE AND
    STOCK_REG.COMCODE=:COM AND
    STOCK_REG.GROUPID = :GID
    UNION ALL
    SELECT -1*QTY,ITEM_CODE,PRICE,DESCR,SALE_DATE FROM
    (select nvl(sales_detailR.qty,0)+NVL(sales_detailR.bonus,0) as qty,
    sales_detailR.item_code AS ITEM_CODE,stock_reg.price as price,
    stock_reg.descr AS descr,
    RETURN_date as sale_date FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.STOCKCODE = STOCK_REG.STOCKCODE AND
    STOCK_REG.COMCODE=:COM AND
    STOCK_REG.GROUPID = :GID
    UNION ALL
    select  -1nvl(sales_detailR.qty,0)+NVL(sales_detailR.bonus,0) as qty,*
    sales_detailR.item_code AS ITEM_CODE,stock_reg.price as price,
    stock_reg.descr AS descr,
    RETURN_date as sale_date  FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.STOCKCODE = STOCK_REG.STOCKCODE AND
    SALES_HEADERR.S_ID = 'MIX' AND
    STOCK_REG.COMCODE=:COM AND
    STOCK_REG.GROUPID = :GID)) S,
    (select level as MONno
    from dual
    connect by level <= 12) d
    where d.MONno = to_char(s.sALE_date, 'MM') AND trunc(S.SALE_DATE,'MONTH') BETWEEN TO_DATE(:FDATE,'MMYY') AND TO_DATE(:TDATE,'MMYY')
    GROUP BY S.ITEM_CODE,S.DESCR,S.PRICE
    ORDER BY S.DESCR ASC

    Gaurav,
    Can you print all the binding variables and update the ouput here.
    And I didn't get this date format 'dd-mon-rrrr', normally it will be like 'dd-mon-yyyy' right?
    Thanks,
    With regards,m
    Kali.
    OSSI.

  • Am.getOADBTransaction().getOrgId() not giving desired result

    Hello,
    I am trying to query Operating Unit in controller of one OAF page.
    Code I tried was
    am.getOADBTransaction().getOrgId(), but it returns -1.
    The responsibility user selects is assigned a Global Security Profile, which has been added only one Operating Unit. So
    I was expecting to get id of that operating unit, but does not work.
    What API should be used in EBS 12 with Multi-Org, to query one or more operating units attached with the responsibility.
    Also when I run
    select * from Per_Security_Profiles on that instance, for the Global security profile in question I see in the table
    organization_id as NULL, though in the forms UI, I can see one operating unit added to this Global Security Profile.
    regards, Yora

    hey,
    If u want the header to get printed once in the main window make a table in that u will have header,main area and footer.
    IF u dont want the header to repeat put the haeder in the header section else if u want the header to repeat then put it in the main area.
    U can check the additional events such as only on first page like that to suffice your requirements.

  • Any one  please correct  this code it is not giving the result as expected.

    class image {
         public int[][] data;
         public int rows;
         public int columns;
    public class BlurImage {
    public int function1(image i1,int k,int j,int rad)
                   int sum=0;
                   int count=0;
                   int R=0,G=0,B=0;
                   String s=new String();
                   for(int x=k-rad;x<=k+rad;x++)
                        if(x<0 || x>=i1.rows)
                             continue;
    for(int y=j-rad;y<=j+rad;y++)
                             if(y<0 || y>=i1.columns)
                                  continue;
    s=Integer.toHexString(i1.data[x][y]).substring(4,6);
                             B=B+Integer.valueOf(s, 16).intValue();
                             s=Integer.toHexString(i1.data[x][y]).substring(2,4);
                             G=G+Integer.valueOf(s, 16).intValue();
                             s=Integer.toHexString(i1.data[x][y]).substring(0,2);
                             R=R+Integer.valueOf(s, 16).intValue();
    count++;
                   R=R/count;
                   G=G/count;
                   B=B/count;
                   System.out.println(" ");
                   String s1=new String();
                   s1=Integer.toHexString(R).concat(Integer.toHexString(G));
                   s1=s1.concat(Integer.toHexString(B));
                   System.out.println(Integer.valueOf(s1, 16).intValue()+" ");
                   return Integer.valueOf(s1, 16).intValue();
    public image blur_image(image i, int radius) {
              //Write your code here
              if(i.rows<radius || i.columns<radius)
                   return null;
              image i1 = new image();
              i1.rows=i.rows;
              i1.columns=i.columns;
              i1.data=new int[i.rows+1][i.columns+1];
              for (int k = 0; k < i.rows; k++)
              for (int j = 0; j < i.columns; j++)
                        if(i.data[k][j]>0xFFFFFF)
                             return null;
                        i1.data[k][j]=(int)function1(i,k,j,radius);
              return i1;
    public static void main(String[] args) {
    //TestCase 1
    try {
    image i = new image();
    i.rows = 5;
    i.columns = 3;
    i.data = new int[][]{{6, 12, 18}, {5, 11, 17}, {4, 10, 16}, {3, 9, 15}, {2, 8, 14}};
    BlurImage obj = new BlurImage();
    image res = obj.blur_image(i, 2);
    System.out.println("TestCase 1");
    if (res != null) {
    for (int k = 0; k < i.rows; k++) {
    System.out.println();
    for (int j = 0; j < i.columns; j++) {
    System.out.print(res.data[k][j] + ",");
    } else
    System.out.println("NULL");
    catch (Exception e) {
                   e.printStackTrace();
    //TestCase 2
    try {
    image i = new image();
    i.rows = 3;
    i.columns = 5;
    i.data = new int[][]{{0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
    {0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038},
    {0x5a0060, 0x6a0050, 0x6a0050, 0x6a0050, 0x7f0038}};
    BlurImage obj = new BlurImage();
    image res = obj.blur_image(i, 1);
    System.out.println("\nTestCase 2");
    if (res != null) {
    for (int k = 0; k < i.rows; k++) {
    System.out.println();
    for (int j = 0; j < i.columns; j++) {
    System.out.print(Integer.toHexString(res.data[k][j])+ ",");
    } else
    System.out.println("NULL");
    catch (Exception e) {
    e.printStackTrace();
    It should give the output as:------
    test case 1:-
    [ 11, 11, 11 ]
    [ 10, 10, 10 ]
    output.data = [ 10, 10, 10 ]
    [ 9,    9,   9  ]
    [ 9,    9,   9  ]
    test case 2:-
    [ 0x620058, 0x640055, 0x6a0050, 0x710048, 0x740044 ]
    output.data = [ 0x620058, 0x640055, 0x6a0050, 0x710048, 0x740044 ]
    [ 0x620058, 0x640055, 0x6a0050, 0x710048, 0x740044 ]

    public class Test
         public static void main(String args[])
              throws Exception
              System.out.println("[ 10, 10, 10 ]");
    }I'll let you customize the above code for test case 2.
    There is not a single comment in the code. We have no idea what the code is supposed to do. We have no idea what you think is wrong. Therefore the above solution is the best we can provide.

Maybe you are looking for

  • Error in MIRO - Moving Average price for the Material is negative?

    Hi, While doing Invoicing, the following error is coming: Moving average price for material is negative: 13070106001 1000 NEW Message no. M8783 Please note that all the Material Qty has been sold out Please help. Regards,

  • Volume structure, surface scan

    I have a new imac, it's been with me for about 2 months total. I noticed some silly little things happening occasionally....so I used tech tools and did a scan. The volume structure failed....and the surface scan has 2 errors. What's the significance

  • InetAddress.getLocalHost retrieving 127.0.0.1, not the actual IP Address

    I am using the following code : try{           InetAddress iaddr = InetAddress.getLocalHost();           String ipaddr = iaddr.getHostAddress();           System.out.println("IP= "+ipaddr);           }catch(UnknownHostException ex){                ex

  • IDOC bad data transfer to XI

    hi. I have a problem. sender system send an IDOC to XI. when I check the IDOC in WE02 found that one of fields of the idoc have a "#" (Torre B1 - B#Unimev). When XI recive the IDOC with XML format the "#" character is transformer to " "(Torre B1 - B

  • Is Dreamweaver the best web design software to learn for an aspiring web designer?

    Hi Everyone, Perhaps difficult to get an unbiased answer to this in a Dreamweaver forum but I'm sure most of you considered other web development software before you went with Dreamweaver. Of course the answer is not as straight forward as just choos