HELP: SELECT MAX( Exp1, Exp2)

SELECT MAX( 1,2,3) FROM DUAL:
Should return 3 but it does not. Each element 1 2 3 is an expression. According to "Oracle 9i SQL Ref" MAX uses standard sql Expressions which Includes an Expression List which is delimited by "," Since SELECT MAX(2) FROM DUAL Returns 2 it should iterate.
I have a table
ID: VAL1: VAL2
I want to query and return 2 columns
ID: MAX(VAL1,VAL2)
I know I probably forgot something stupid.
Thank you for any help.

max finds the maximum value from one column (or expression) from multiple rows.
so this will work:
select max(x) from (
select 1 x from dual
union
select 2 from dual
union
select 3 from dual
to find the maximum value from different columns from one row use "greatest".
select greatest(1,2,3) from dual;

Similar Messages

  • Help sql-- select max

    I would select max from a table.
    For example the table is:
    Person with Name Surname Age and i want to extract the perso with max(age).
    If i write:
    select max(age), nome
    from person
    group by nome;
    the outpup isn't Person1 30
    but person1 30
    person2 25
    How can i do it? Thanks.

    REM*************************************************************
    REM* Tabella TIPO_ATTIVITA' *
    REM*************************************************************
    DROP TABLE tipo_attivita
    CREATE TABLE tipo_attivita
    (Id_tipo_attivita VARCHAR2(1) NOT NULL ---(PK)
    ,tipo_attivita VARCHAR2(1) NOT NULL --('F'atturato, 'N'on fatturato)
    ,desc_tipo_attivita VARCHAR2(60) NOT NULL
    ,note_tipo_attivita VARCHAR2(2000)      
    TABLESPACE dbsr_hr
    INSERT INTO tipo_attivita VALUES ('F','N','Formazione',NULL);
    INSERT INTO tipo_attivita VALUES ('I','N','Attività Interna',NULL);
    INSERT INTO tipo_attivita VALUES ('C','F','Attività Remunerata da commessa Cliente',NULL);
    INSERT INTO tipo_attivita VALUES ('N','N','Attività ad investimento sul Cliente',NULL);
    COMMIT;
    REM*************************************************************
    REM* Tabella PERSONALE *
    REM*************************************************************
    DROP TABLE personale
    CREATE TABLE personale
    (Id_personale number(4) NOT NULL --(PK)
    ,cognome varchar2(20) NOT NULL
    ,nome varchar2(20) NOT NULL
    ,residuo_ferie_anno_08 NUMBER(2) -- in giorni. E' il residuo al 31/12/08 che nel frattempo puo' essere stato consumato
    ,residuo_permessi_anno_08 NUMBER(2) -- in ore. E' il residuo al 31/12/08 che nel frattempo puo' essere stato consumato
    TABLESPACE dbsr_hr
    REM*************************************************************
    REM* Tabella delle ATTIVITA *
    REM*************************************************************
    DROP TABLE attivita
    CREATE TABLE attivita
    (Id_attivita number(4) NOT NULL --(PK)
    ,Id_tipo_attivita VARCHAR2(1) NOT NULL --(FK)
    ,desc_breve_attivita varchar2(60) NOT NULL
    ,data_inizio_att DATE NOT NULL
    ,data_fine_att DATE
    ,Id_cliente number(4) --(FK)
    ,desc_lunga_attivita varchar2(2000)
    ,note_attivita varchar2(2000)
    TABLESPACE dbsr_hr
    REM *************************************************************
    REM * Tabella FOGLIO ORE*
    REM *************************************************************
    DROP TABLE foglio_ore
    CREATE TABLE foglio_ore
    (data DATE NOT NULL
    ,Id_personale NUMBER(4) NOT NULL --(FK)
    ,Id_giustificativo NUMBER(2) NOT NULL --(FK)
    ,ore NUMBER(2) NOT NULL
    ,Id_attivita NUMBER(4) --(FK)
    ,ora_inizio          DATE
    ,ora_fine DATE
    ,note_foglio_ore VARCHAR2(250)
    TABLESPACE dbsr_hr
    /

  • Select Max and ResultSet Problem With Access

    The following code is producing a 'null pointer excepetion' error and I know why it is occurring I just do not know how to fix the problem.
    Basically I want to automitically generate a unique ID that is one number higher than the max ID (data is stored within an Access database). The ID field is made up of first and last initial taken from parsing previous login info ('JS-01', 'JS-02', ect.). If there are no IDs in the database that match your login info I want to set the new ID equal to 'JS-01' if your login is 'James Smith' for example.
    The problem is explained within the code below.
    <%
    //define resultset and statement
    ResultSet rss=null;
    ResultSet rs=null;
    Statement stmt=null;
    //HERE IS WHERE YOU PARSE THE LOGIN INFO
    String finitial = (String)session.getAttribute("vfirst");//vfirst=JIM
    String linitial = (String)session.getAttribute("vlast");//vlast=SMITH
    char f = finitial.charAt(0);
    char n = linitial.charAt(0);
    String sID = f+""+n;//NOW sID CONTAINS 'JS'
    try {
    //Using the current database connection create a statement
    stmt=con.createStatement();
    //QUERY TO SELECT MAX ID
    //NOTE: CURRENTLY THERE ARE NO IDs LIKE 'JS' IN THE DATABASE !!!!!!
    String sql="SELECT Max(ID) As MaxID FROM tblError Where ID LIKE '%"+sID+"%'" ;
    rs = stmt.executeQuery(sql);
    String newID;
    //HERE THE RESULT SET SHOULD BE NULL BUT IT IS NOT. I KNOW THIS BECAUSE WHEN I REPLACE String iID WITH A LITERAL LIKE 'JS-03' THE LOGIC WILL EXECUTE CORRECTLY AND GIVE ME 'JS-04'. IF I LEAVE THE CODE LIKE IT IS THEN I GET THE NULL POINTER VALUE ERROR BECAUSE YOU CANNOT RESOLVE "MaxID" WHEN THE RESULT SET IS NULL. IF THE RESULT SET IS NULL IT SHOULD NOT EVEN EXECUTE ANY OF THIS CODE WITHIN THE 'if' STATEMENT, BUT IT IS. SO BASICALLY JSP IS LEAVING ME WITH A MAJOR OXYMORON AND I WOULD APPRECIATE ANY ADVICE THAT WOULD HELP ME SOLVE THIS PROBLEM.
    if(rs.next()){
    String iID = rs.getString("MaxID");
    String letters = iID.substring(0,3);
    int numbers = Integer.parseInt(iID.substring(3,5));
    numbers = numbers + 1;
    if(numbers < 10){
    newID = letters + "0" + numbers;}
    else{
    newID = letters + numbers;
    else{//IF THERE IS NO RESULT SET THAN THE ID SHOULD BE 'JS-01'
    newID = sID + "-01";
    %>
    Because this an Access database I cannot use any null exception functions such as NVL or COALESCE which are specific to Oracle and SQL Server I beleive.

    The max() will return a result set, even if the max value is null.
    You should check to see if iID is null.
    if(rs.next())
       String iID = rs.getString("MaxID");
       if (iID == null)
           newID = sID + "-01";
       else
          String letters = iID.substring(0,3);
          ... etc ...
    }

  • Select Max record for the report

    Post Author: ROMZILBER
    CA Forum: WebIntelligence Reporting
    Hello,
    Here is our problem we have history data on a table like
    Example
    Data:
    11111   bbb       12/31/2004
    11111   nnn       12/31/2005
    11111   ddd       12/31/2007
    On a report we only need to display the most current record (based on a date).
    11111   ddd       12/31/2007
    How can we do that, we have try to create subquery but it does not allowed to enter logic for the max date for the same id.  So we are kind of stuck, I am more then sure this would be a very common conditions specially for data warehousing.
    we are on Oracle 10g
    Thank you for all your help.

    Post Author: ROMZILBER
    CA Forum: WebIntelligence Reporting
    To create a view is not a problem, supporting it is a different story
    But we have find a solution, you were correct about the filter.  I just did not know you can put the whole subselect in a  filter
    but here is a logic for the filter if someone would come up with the same problem
    tablename.NNNN_PROOF_DT = (SELECT MAX(X.NNNN_PROOF_DT) FROM tablename X  WHERE tablename.NNNN_CLAIM_NUMBER = X.NNNN_CLAIM_NUMBER AND   tablename.NNNN_LINE_CD = X.NNNN_LINE_CD)
    please let me know if you have any questions.
    sorry I am new to this so please do not take any offense

  • How to select Max in a multi query?

    Hi all,
    I got this query:
    select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2;
    I want to get single row from the results of this query, so I may use MAX or MIN or where rownum<2.
    How can I do this please....
    I tried: SELECT MAX(select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2) from DUAL;
    but I got syntax error :(
    Please help....
    Thanks

    select DEPTNO, EMPNO from EMP1 minus select DEPTNO, EMPNO from EMP2;
    I want to get single row from the results of this querywhich row is correct row & why?
    How many rows returned now? (Since we don't have your tables or data.)
    Handle:      KinsaKaUy?
    Status Level:      Newbie
    Registered:      Mar 9, 2011
    Total Posts:      614
    Total Questions:      168 (110 unresolved)
    so many questions & so few answers.
    How SAD!
    Edited by: sb92075 on Aug 29, 2011 11:10 AM

  • Same select max is very slow in one program but fast in another

    Hi,
    I have a report that becomes very slow these few months. I used SQL trace for the report and found out its these codes that slow down the report:
    SELECT MAX( mkpf~budat )
                  FROM mkpf
        INNER JOIN mseg
                       ON mseg~mblnr = mkpf~mblnr AND mseg~mjahr = mkpf~mjahr
                    INTO posting_date
               WHERE mseg~werks  = w_matl-batch_reservations-werks
                     AND mseg~charg  = w_matl-batch_reservations-charg
                     AND mseg~bwart  IN ('261', 'Z61').
    The thing is these codes have been used in different system, DEV, QAS, and PRD. But only in PRD it is very slow, other systems are pretty fast.
    I even created a local copy of that report in PRD, with the same code. The local file runs fast and perfectly. But the original code is just slow.
    Just wondering if anybody met this problem too? any ideas??

    Hi Liu,
    Index creation is not a advisable solution.Please follow the existing indexes by adding Mandt field.
    Try like this
    SELECT MAX( mkpf~budat )
                  FROM mkpf
        INNER JOIN mseg
                       ON mseg~mblnr = mkpf~mblnr AND mseg~mjahr = mkpf~mjahr
                    INTO posting_date
               WHERE mseg~mandt = sy-mandt
                      AND mkpf~mandt = sy-mandt
                      AND mseg~werks  = w_matl-batch_reservations-werks
                     AND mseg~charg  = w_matl-batch_reservations-charg
                     AND mseg~bwart  IN ('261', 'Z61').
    Hope it will be helpful.
    Regards,
    Kannan

  • How to use select max and min query..

    hi gurus,
    we have got a custom report for develoment.
    the report has to fetch the max and min salarys department wise....
    how to pick up max & min sal ansal from table pa0008.

    Hi,
    Try the following
    select max(sal)
               min(sal)
               from <database table>
               into <internal table>
               group by department
               where <where condition>.
    Here we assume that sal is the field holding the salary and department is the name of the field in the database table. Where condition is optional.
    Hope this helps.
    Regards,
    Sachin

  • Problem selecting MAX YEAR MAX MONTH MAX DATE in one query

    CREATE TABLE TEMP
    C_INVOICE_ID NUMBER(10),
    DIA NUMBER,
    MES NUMBER,
    ANO NUMBER,
    SOCIO_NEGOCIO NVARCHAR2(60) NOT NULL,
    PRODUCTO_NOM NVARCHAR2(60) NOT NULL,
    M_PRODUCT_ID NUMBER(10),
    CATEGORIA NVARCHAR2(60) NOT NULL,
    COSTO NUMBER
    INSERT INTO TEMP VALUES(10111,1,2,2010,'1585','ALURON 100MG X 30 TABLETAS',1530,15,1.15);
    INSERT INTO TEMP VALUES(1015,15,2,2010,'1520','ALURON 100MG X 30 TABLETAS',1530,15,2.15);
    INSERT INTO TEMP VALUES(5654,5,2,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.2);
    INSERT INTO TEMP VALUES(15321,4,6,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
    INSERT INTO TEMP VALUES(13548,8,6,2010,'1585','AMARYL 2MG X 15 TABLETAS',1531,15,4.3);
    INSERT INTO TEMP VALUES(19456,31,4,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4);
    INSERT INTO TEMP VALUES(116544,8,8,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
    INSERT INTO TEMP VALUES(132,2,3,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.1);
    INSERT INTO TEMP VALUES(168,15,1,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.9);
    INSERT INTO TEMP VALUES(4898,7,4,2010,'1220','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
    INSERT INTO TEMP VALUES(15132,25,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.4);
    INSERT INTO TEMP VALUES(1684,18,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.3);
    INSERT INTO TEMP VALUES(14988,8,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,2.9);
    INSERT INTO TEMP VALUES(84941,8,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.1);
    INSERT INTO TEMP VALUES(1155,7,4,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.7);
    INSERT INTO TEMP VALUES(184,1,1,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
    INSERT INTO TEMP VALUES(48994,8,4,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.7);
    INSERT INTO TEMP VALUES(1465465,9,5,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
    INSERT INTO TEMP VALUES(16,18,6,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
    INSERT INTO TEMP VALUES(894886,20,4,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
    CREATE TABLE TEMP
    C_INVOICE_ID NUMBER(10),
    DIA NUMBER,
    MES NUMBER,
    ANO NUMBER,
    SOCIO_NEGOCIO NVARCHAR2(60) NOT NULL,
    PRODUCTO_NOM NVARCHAR2(60) NOT NULL,
    M_PRODUCT_ID NUMBER(10),
    CATEGORIA NVARCHAR2(60) NOT NULL,
    COSTO NUMBER
    INSERT INTO TEMP VALUES(10111,1,2,2010,'1585','ALURON 100MG X 30 TABLETAS',1530,15,1.15);
    INSERT INTO TEMP VALUES(1015,15,2,2010,'1520','ALURON 100MG X 30 TABLETAS',1530,15,2.15);
    INSERT INTO TEMP VALUES(5654,5,2,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.2);
    INSERT INTO TEMP VALUES(15321,4,6,2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
    INSERT INTO TEMP VALUES(13548,8,6,2010,'1585','AMARYL 2MG X 15 TABLETAS',1531,15,4.3);
    INSERT INTO TEMP VALUES(19456,31,4,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4);
    INSERT INTO TEMP VALUES(116544,8,8,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);
    INSERT INTO TEMP VALUES(132,2,3,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.1);
    INSERT INTO TEMP VALUES(168,15,1,2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.9);
    INSERT INTO TEMP VALUES(4898,7,4,2010,'1220','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
    INSERT INTO TEMP VALUES(15132,25,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.4);
    INSERT INTO TEMP VALUES(1684,18,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.3);
    INSERT INTO TEMP VALUES(14988,8,8,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,2.9);
    INSERT INTO TEMP VALUES(84941,8,9,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.1);
    INSERT INTO TEMP VALUES(1155,7,4,2010,'1585','AMOXAL 250MG X 75ML SUSPENSION',1534,15,4.7);
    INSERT INTO TEMP VALUES(184,1,1,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
    INSERT INTO TEMP VALUES(48994,8,4,2010,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.7);
    INSERT INTO TEMP VALUES(1465465,9,5,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.8);
    INSERT INTO TEMP VALUES(16,18,6,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
    INSERT INTO TEMP VALUES(894886,20,4,2009,'1520','AMOXAL 250MG X 75ML SUSPENSION',1534,15,3.9);
    I have this query so far,
    SELECT
    MAX (TEMP.COSTO) COSTO,
    TEMP.M_PRODUCT_ID,
    TEMP.ANO
    FROM TEMP TEMP
    INNER JOIN(
    SELECT MAX(ANO) ANO, M_PRODUCT_ID
    FROM TEMP I
    GROUP BY M_PRODUCT_ID
    ) LA ON LA.ANO = TEMP.ANO AND LA.M_PRODUCT_ID = TEMP.M_PRODUCT_ID
    GROUP BY
    TEMP.M_PRODUCT_ID,
    TEMP.ANO
    but my intention is not to have the max cost, my intention is to query in this order
    first i need to select distinct m_product_id then
    for every m_product_id i need to
    filter max (ano) then filter max (mes) then filter max (dia)
    I need the result set like this.
    C_INVOICE_ID DIA MES ANO SOCIO PRODUCTO_NOM M_PRODUCT_ID CATERGORIA COSTO
    1015 15 2 2010 1520 ALURON 100MG X 30 TABLETAS 1530 15 2.15
    5654 5 2 2010 1520 AMARYL 2MG X 15 TABLETAS 1531 15 4.2
    15132 25 9 2010 1585 AMOXAL 250MG X 75ML SUSPENSION 1534 15 3.4
    please i really apritiated any help, thanks pd:i'm using oracle 9i

    Hi,
    Thanks for posting the CREATE TABLE and INSERT statements. Why are there two tables, and two sets of data? Was that a mistake?
    Sorry, I don't uderstand the problem.
    For m_product_id=1531, for example, why do you want
    INSERT INTO TEMP VALUES(5654,     5, 2, 2010,'1520','AMARYL 2MG X 15 TABLETAS',1531,15,4.2);selected, and not
    INSERT INTO TEMP VALUES(116544,     8, 8, 2010,'1220','AMARYL 2MG X 15 TABLETAS',1531,15,4.8);Both rows have ano=2010, so don't you want the one with the higher mes (8 > 2)?
    I think what you'll want is a Top-N Query , something like this:
    WITH     got_r_num     AS
         SELECT     temp.*     -- or list columns you want
         ,     RANK () OVER ( PARTITION BY  m_product_id
                          ORDER BY          ano     DESC     NULLS FIRST
                          ,          mes     DESC     NULLS FIRST
                          ,          dia     DESC     NULLS FIRST
                        )          AS r_num
         FROM     temp
    --     WHERE     ...     -- any filtering goes here
    SELECT     *     -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;What if there's a tie? For example, if you add another row to the sample data:
    INSERT INTO TEMP VALUES(9876,     15,2, 2010,'1520','ALURON 100MG X 30 TABLETAS',1530,15,2.15);The query above would include both c_invoice_id=9876 and 1015. If you want just one of those rows, add more expressions to the analytic ORDER BY clause and/or use ROW_NUMBER instead of RANK.

  • Select MAX(BUDAT) from ztab (custom table) where... NOT work!

    We use the following statement where BUDAT is one of the fields in our custom table ztab:
    Select MAX(BUDAT) from ztab (custom table) where...
    When activating the above code, get the following error:
    "Unknown column name "MAX(BUDAT)". not determined until runtime, you cannot specify a field list."
    How to resolve this problem to get a max value of the field BUDAT in custom table ztab (it's not an internal table)?
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Apr 10, 2008 3:56 PM

    HI,
    Tyr having a space after and before BUDAT.
    ( BUDAT ).
    Hope it helps,
    Shreekant

  • SELECT MAX(field) / SELECT MIN(field) return wrong values

    Hi,
    I have the query:
    Select 
        MAX(b1.time_s) as time_s 
    From
        BUSINESS_INVOCATIONS b1 
    Where
        b1.time_s >= 1219217034000 
        AND  b1.rec_sess_id = 2197756621378027521 
        AND  b1.comp_id IN  ( Select id  From J2EE_CONFIGURATION_BEAN  Where j2eeApplicationsTableId = 378302371920347137 )
    This return the MAX value of the comp_id and not the MAX value of the b1.time_s
    looks like there is a BUG in MAXDB when i have a join of two tables the MAX/MIN functions works on the wrong fields!
    If i change the query to be:
    Select 
        max(b1.time_s) as time_s 
    From
        BUSINESS_INVOCATIONS b1,
        J2EE_CONFIGURATION_BEAN jcb
    Where
        b1.time_s >= 1219217034000 
        AND  b1.rec_sess_id = 2197756621378027521
        AND jcb.j2eeApplicationsTableId = 378302371920347137
        AND  b1.comp_id = jcb.id
    The MIN/MAX functions works good and return the right value
    Pleasehelp me to find what is the problem and if any one already have a solution.
    Thanks,
    Yosef

    Dta for BUSINESS_INVOCATIONS tabel:
    ID,CLASS_TYPE,M_TIME,FUNCTIONENTRYID,TOP_PARENT,START_TIME,TIME_S,COMP_ID,REC_SESS_ID,PARENT,HTTP_SESSION,INVOCATION_HASH_CODE,MINOR_INVOCATION,TRANSACTION_ID,USER_TRACING_COOKIE,TRACINGTYPE
    2089670230321135617,H,1219738865499,1387108688451338241,2089670230321135617,1219217053734,1219217053734,414331168939311111,2197756621378027521,(null),2179742222868545537,-1238173181,GET,null,null,-1
    2089670230321135618,H,1219738865499,1387108688451338242,2089670230321135618,1219217071156,1219217071156,414331168939311108,2197756621378027521,(null),2179742222868545538,-628203986,GET,null,null,-1
    2089670230321135619,H,1219738865499,1387108688451338279,2089670230321135619,1219217073531,1219217073531,414331168939311112,2197756621378027521,(null),2179742222868545538,545948335,GET,null,null,-1
    2089670230321135620,H,1219738865499,1387108688451338284,2089670230321135620,1219217075671,1219217075671,414331168939311119,2197756621378027521,(null),2179742222868545538,1958406838,GET,null,null,-1
    2089670230321135621,H,1219738865499,1387108688451338289,2089670230321135621,1219217077359,1219217077359,414331168939311106,2197756621378027521,(null),2179742222868545538,-2089005650,GET,null,null,-1
    2089670230321135622,H,1219738865499,1387108688451338292,2089670230321135622,1219218442312,1219218442312,414331168939311115,2197756621378027521,(null),2179742222868545538,-1298180580,GET,null,null,-1
    2089670230321135623,H,1219738865499,1387108688451338297,2089670230321135623,1219218467765,1219218467765,414331168939311107,2197756621378027521,(null),2179742222868545538,1318337921,GET,null,null,-1
    2107684628830617601,E,1219738865515,1387108688451338244,2089670230321135618,1219217071171,1219217071171,324259176391901185,2197756621378027521,2089670230321135618,2179742222868545538,586868856,(null),(null),(null),-1
    2107684628830617602,E,1219738865515,1387108688451338281,2089670230321135619,1219217073531,1219217073531,324259176391901185,2197756621378027521,2089670230321135619,2179742222868545538,1886325459,(null),(null),(null),-1
    2107684628830617603,E,1219738865515,1387108688451338286,2089670230321135620,1219217075671,1219217075671,324259176391901185,2197756621378027521,2089670230321135620,2179742222868545538,-550916224,(null),(null),(null),-1
    2107684628830617604,E,1219738865515,1387108688451338291,2089670230321135621,1219217077359,1219217077359,324259176391901185,2197756621378027521,2089670230321135621,2179742222868545538,1676270392,(null),(null),(null),-1
    2107684628830617605,E,1219738865515,1387108688451338294,2089670230321135622,1219218442312,1219218442312,324259176391901185,2197756621378027521,2089670230321135622,2179742222868545538,-2074647744,(null),(null),(null),-1
    2107684628830617606,E,1219738865515,1387108688451338299,2089670230321135623,1219218467765,1219218467765,324259176391901185,2197756621378027521,2089670230321135623,2179742222868545538,63795915,(null),(null),(null),-1
    3278620531946946561,T,1219738865483,1387108688451338291,2089670230321135621,1219217077359,1219217077359,2828260569209896968,2197756621378027521,2107684628830617604,2179742222868545538,-1511714853,java.lang.ArithmeticException,(null),(null),18
    Daa for J2EE_CONFIGURATION_BEAN Table:
    select * from IDENTIFY.J2EE_CONFIGURATION_BEAN
    ID,J2EEAPPLICATIONSTABLEID,J2EEAPPLICATIONID,J2EECOMPONENTID
    180144094616485889,0,0,0
    180144094616485890,0,0,0
    180144094616485891,0,0,0
    180144094616485892,0,0,0
    180144094616485893,378302478220787713,0,0
    180144094616485894,0,0,0
    306244884182859777,378302478220787713,360288079711305731,306244884182859777
    324259282692341761,378302478220787713,360288079711305731,306244884182859777
    360288079711305729,378302478220787713,360288079711305729,0
    360288079711305730,378302478220787713,360288079711305730,0
    360288079711305731,378302478220787713,360288079711305731,0
    360288079711305732,378302478220787713,360288079711305732,0
    360288079711305733,378302478220787713,360288079711305733,0
    360288079711305734,378302478220787713,360288079711305734,0
    414331275239751681,378302478220787713,360288079711305731,594475260334571522
    414331275239751682,378302478220787713,360288079711305731,594475260334571522
    414331275239751683,378302478220787713,360288079711305731,594475260334571522
    414331275239751684,378302478220787713,360288079711305731,594475260334571522
    414331275239751685,378302478220787713,360288079711305731,594475260334571522
    414331275239751686,378302478220787713,360288079711305731,594475260334571522
    414331275239751687,378302478220787713,360288079711305731,594475260334571522
    414331275239751688,378302478220787713,360288079711305731,594475260334571522
    414331275239751689,378302478220787713,360288079711305731,594475260334571522
    414331275239751690,378302478220787713,360288079711305731,594475260334571522
    414331275239751691,378302478220787713,360288079711305731,594475260334571522
    414331275239751692,378302478220787713,360288079711305731,594475260334571522
    414331275239751693,378302478220787713,360288079711305731,594475260334571522
    414331275239751694,378302478220787713,360288079711305731,594475260334571522
    414331275239751695,378302478220787713,360288079711305731,594475260334571522
    540432064806125569,378302478220787713,360288079711305732,594475260334571523
    540432064806125570,378302478220787713,360288079711305732,594475260334571523
    540432064806125571,378302478220787713,360288079711305732,594475260334571523
    540432064806125572,378302478220787713,360288079711305732,594475260334571523
    540432064806125573,378302478220787713,360288079711305732,594475260334571523
    540432064806125574,378302478220787713,360288079711305732,594475260334571523
    540432064806125575,378302478220787713,360288079711305734,594475260334571524
    540432064806125576,378302478220787713,360288079711305734,594475260334571524
    576460861825089537,378302478220787713,360288079711305730,576460861825089537
    576460861825089538,378302478220787713,360288079711305731,576460861825089538
    576460861825089539,378302478220787713,360288079711305732,576460861825089539
    576460861825089540,378302478220787713,360288079711305733,576460861825089540
    576460861825089541,378302478220787713,360288079711305734,576460861825089541
    594475260334571521,378302478220787713,360288079711305729,594475260334571521
    594475260334571522,378302478220787713,360288079711305731,594475260334571522
    594475260334571523,378302478220787713,360288079711305732,594475260334571523
    594475260334571524,378302478220787713,360288079711305734,594475260334571524
    2810246277000855553,378302478220787713,360288079711305729,2810246277000855553
    2810246277000855554,378302478220787713,360288079711305729,2810246277000855554
    2810246277000855555,378302478220787713,360288079711305729,2810246277000855555
    2810246277000855556,378302478220787713,360288079711305729,2810246277000855556
    2810246277000855557,378302478220787713,360288079711305729,2810246277000855557
    2810246277000855558,378302478220787713,360288079711305729,2810246277000855558
    2810246277000855559,378302478220787713,360288079711305729,2810246277000855559
    2828260675510337537,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337538,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337539,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337540,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337541,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337542,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337543,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337544,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337545,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337546,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337547,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337548,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337549,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337550,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337551,378302478220787713,360288079711305729,2846275074019819521
    2828260675510337552,378302478220787713,360288079711305729,2846275074019819521
    2846275074019819521,378302478220787713,360288079711305729,2846275074019819521
    3152519848681013249,378302478220787713,360288079711305729,3152519848681013249
    3152519848681013250,378302478220787713,360288079711305730,3152519848681013250
    3152519848681013251,378302478220787713,360288079711305731,3152519848681013251
    3152519848681013252,378302478220787713,360288079711305732,3152519848681013252
    3152519848681013253,378302478220787713,360288079711305733,3152519848681013253
    3152519848681013254,378302478220787713,360288079711305734,3152519848681013254
    3170534138742571009,0,0,0
    3170534138742571010,0,0,0
    3170534247190495233,0,0,0
    3170534247190495234,0,0,0
    3602879811418062849,378302478220787713,360288079711305729,594475260334571521
    Hope this will help:)
    Thanks,
    Yosef

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

  • How to select max (field) and one more field from table?

    Hi experts!
    I need to select maximum value of ENDDA from PA0023 and BRANC of max ENDDA.
    How can I do that ?
    When I trying this code:
    This is the  code:
    SELECT MAX( endda ) branc
      FROM pa0023
      INTO (pa0023-endda, pa0023-branc).
    I get error message:
    The field "PA0023~BRANC" from the SELECT list is missing
    in the GROUP BY clause. Addition INTO wa or INTO (g1,...,gn)  is required.
    So what is the problem?
    Thanks forehead.

    Hi
    Though am not totally sure of your requirement, check below code samples without any syntax errors:
    1. As per you current coding:
    TABLES: pa0023.
    SELECT MAX( endda ) branc
           FROM pa0023
           INTO (pa0023-endda, pa0023-branc)
           GROUP BY branc.
    ENDSELECT.
    2. Above code results only on one record where as the criteria can be more than one. Eg: for a specific data more than one record can exist. Below code helps you handle the same:
    TABLES: pa0023.
    TYPES: BEGIN OF t_pa0023,
             endda TYPE endda,
             branc TYPE brsch,
           END OF t_pa0023.
    DATA: i_pa0023 TYPE TABLE OF t_pa0023,
          wa_pa0023 TYPE t_pa0023.
    SELECT MAX( endda ) branc
           FROM pa0023
           INTO TABLE i_pa0023
           GROUP BY branc.
    LOOP AT i_pa0023 INTO wa_pa0023.
    ENDLOOP.
    3. If the requirement is to get the Industry Key for the record with highest End Date. We can acheive it by using subquery something like:
    TABLES: pa0023.
    SELECT SINGLE endda branc
           FROM pa0023
           INTO (pa0023-endda, pa0023-branc)
           WHERE endda = ( SELECT MAX( endda ) FROM pa0023 ).
    Kind Regards
    Eswar

  • How to : SELECT MAX(EmpID) / count(*) in SELECT Query

    Hi,
    I like to find out the Maximum of the EmpID that is in the DB table.
    So I need to perform a select Query:
    Select MAX(EmpID) from EmpTable
    or Select Count(*) from EmpTable
    <StatementName>
    <dbTableName action=”SELECT”>
       <table>realDbTableName</table>
         <access>
             <??? />
          </access>
    </dbTableName> 
    </StatementName>
    I cannot type MAX(EmpID) or count(*) as access element
    So what should I mention in the Access?
    Thanks & regards,
    Siva Maranani.

    if 0CALDAY is used as a characteristic then you have to convert that as a key figure using a replacement path variable.
    Please see the below link for changing 0CALDAY as a key figure using Replacement path
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    https://websmp106.sap-ag.de/~sapdownload/011000358700001963972003E/HowToCalcWithAttr.pdf
    Now you have to create an exception "Top N Rows" based on the replacement path variable created above.
    This will solve your problem.
    Regs
    Gopi.
    Award points if it helps ...

  • SELECT MAX query

    Hai Friends,
    The following is my select query
    SELECT MAX( MBLNR )
    FROM ZMIGO
    INTO TABLE IT_MAX.
    Right now my Z table is empty. but when i debug the program it showing 1 entry and when i double the internal table there is no value and it is blank. why it is showing as 1 entry.

    Hi,
    Try using:-
    DATA : v_mblnr TYPE zmigo-mblnr.
    SELECT MAX( DISTINCT mblnr ) FROM zmigo INTO v_mblnr.
    IF sy-subrc NE 0.
      CLEAR v_mblnr.
    ENDIF.
    Hope this helps you.
    Regards,
    Tarun

  • SQL query problem - select max (case... aggregate function)

    Hi,
    I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
    select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
    select
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    Any ideas?

    Moved to more sutable forum, sorry.

Maybe you are looking for