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
/

Similar Messages

  • 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 ...
    }

  • 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;

  • SQL Command to select MAX(date) & Max(time)

    My am having a really hard time getting a sql command to return data with the max(date) & max(time) combination. I think I need a sub query but can not figure it out. I have looked all over the internet but still don't understand it. Below is my command which returns the max date & max time but they are not from the same row of data. Please help.
    SELECT  "labor"."order-no", "labor"."oper-no", MAX("labor"."end-date") AS myDate, Max("labor"."end-time") AS myTime
    FROM   "E940LIVE"."PUB"."tm-log" "labor"
    WHERE  "labor"."order-no"='73153-bc' AND "labor"."company"='01'
    GROUP BY  "labor"."order-no", "labor"."oper-no"

    Progress does not support the DATEADD function. Waht if I forget the number is time and look at it just as a number. Here is my data and what I have tried (again I don't understand the multiple select concept yet).
    Data
    oper-no   end-date    end-time
      20      2/2/2010     41,975
      30      2/3/2010     45,906
      30      2/16/2010    32,941
      40      2/4/2010     46,099
      40      2/4/2010     50,227
      40      2/4/2010     59,466
      40      2/4/2010     62,024
      40      2/16/2010    43,838
      60      2/17/2010    32,679
      90      2/25/2010    35,270
    SQL Command
    SELECT a."oper-no", a."end-time", a."end-date"
    FROM   "E940LIVE"."PUB"."tm-log" a, (SELECT "end-time", max("end-date") AS max_date FROM "E940LIVE"."PUB"."tm-log" WHERE  "order-no"='73153-bc' AND "company"='01' GROUP BY "end-date", "end-time") b
    WHERE  a."end-time" = b."end-time" AND a."end-date" = b.max_date AND a."order-no"='73153-bc' AND a."company"='01'
    Result
    oper-no   end-date     end-time
      20      2/2/2010      41,975
      30      2/3/2010      45,906
      40      2/4/2010      50,227
      40      2/4/2010      46,099
      40      2/4/2010      59,466
      40      2/4/2010      62,024
      30      2/16/2010     32,941
      40      2/16/2010     43,838
      60      2/17/2010     32,679
      90      2/25/2010     35,270
    Desired Result
    oper-no   end-date    end-time
      20      2/2/2010     41,975
      30      2/16/2010    32,941
      40      2/16/2010    43,838
      60      2/17/2010    32,679
      90      2/25/2010    35,270
    Thanks for any and all help!
    Wayne

  • Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field

    Hello,
    I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
    Table structures are mentioned below:
    OP:
    Name                             Null                    Type        
    OP_NBR                    NOT NULL      NUMBER(4)    (Primary Key)
    OP_DESC                                        VARCHAR2(50)
    OP_PAYLOD_XML                           CLOB       
    GM:
    Name                          Null                   Type        
    GM_NBR                  NOT NULL       NUMBER(4)    (Primary Key)
    GM_DESC                                       VARCHAR2(40)
    OP_NBR               NOT NULL          NUMBER(4)    (Foreign Key)
    GM_PAYLOD_XML                          CLOB   
    DM:
    Name                          Null                    Type        
    DM_NBR                  NOT NULL         NUMBER(4)    (Primary Key)
    DM_DESC                                         VARCHAR2(40)
    GM_NBR                  NOT NULL         NUMBER(4)    (Foreign Key)
    DM_PAYLOD_XML                            CLOB       
    DE:
    Name                          Null                    Type        
    DE_NBR                     NOT NULL           NUMBER(4)    (Primary Key)
    DE_DESC                   NOT NULL           VARCHAR2(40)
    DM_NBR                    NOT NULL           NUMBER(4)    (Foreign Key)
    DE_PAYLOD_XML                                CLOB    
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    SELECT
    j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
    i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
    h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
    g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
    FROM
    DE g, DM h, GM i, OP j
    WHERE
    h.dm_nbr = g.dm_nbr(+) and
    i.gm_nbr = h.gm_nbr(+) and
    j.op_nbr = i.op_nbr(+)
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
    Current O/P:
    <resultSet>
         <Record1>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <DM_PAYLOD_XML1>
              <DE_PAYLOD_XML1>
         </Record1>
         <Record2>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML2>
              <DM_PAYLOD_XML2>
              <DE_PAYLOD_XML2>
         </Record2>
         <RecordN>
              <OP_PAYLOD_XMLN>
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XMLN>
         </RecordN>
    </resultSet>
    Now i want to change my SQL query so that i get following output structure:
    <resultSet>
         <Record>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <GM_PAYLOD_XML2> .......
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XML1>
              <DM_PAYLOD_XML2> .......
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XML1>
              <DE_PAYLOD_XML2> .......
              <DE_PAYLOD_XMLN>
         </Record>
         <Record>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML1'>
              <GM_PAYLOD_XML2'> .......
              <GM_PAYLOD_XMLN'>
              <DM_PAYLOD_XML1'>
              <DM_PAYLOD_XML2'> .......
              <DM_PAYLOD_XMLN'>
              <DE_PAYLOD_XML1'>
              <DE_PAYLOD_XML2'> .......
              <DE_PAYLOD_XMLN'>
         </Record>
    <resultSet>
    Appreciate your help in this regard!

    Hi,
    A few questions :
    How's your first query supposed to give you an XML output like you show ?
    Is there something you're not telling us?
    What's the content of, for example, <OP_PAYLOD_XML1> ?
    I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
    What's the db version BTW?

  • 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.

  • SQL SELECT statement Parent_child table and its related table..... HELP plz

    I have 2 tables
    Table Parent_child_table:
    ID | Parent_id | Name
    1 | NULL | Kitchen
    2 | 1 | Freezer
    3 | NULL | Garden
    4 | 3 | Grass
    Table Products:
    ID | parent_child_table_ID | Price | Comment
    1 | 2 | 111 | aaaa
    2 | 4 | 12 | vv
    I want to select Name from parent table where selected child ID are in PRODUCT table.....
    The result would like:
    |NAME|
    |Kitchen
    |Garden
    Can someone help with this SQL SELECT ?

    Raivis wrote:
    I have 2 tables
    Table Parent_child_table:
    ID | Parent_id | Name
    1 | NULL | Kitchen
    2 | 1 | Freezer
    3 | NULL | Garden
    4 | 3 | Grass
    Table Products:
    ID | parent_child_table_ID | Price | Comment
    1 | 2 | 111 | aaaa
    2 | 4 | 12 | vv
    I want to select Name from parent table where selected child ID are in PRODUCT table.....
    The result would like:
    |NAME|
    |Kitchen
    |Garden
    Can someone help with this SQL SELECT ?A guess
    select
       p.name
    from Parent_child_table p
    where p.parent_id is null
    and exists
    select
       null
    from Parent_child_table p1, products p2
    where p1.id = p2. parent_child_table_id
    and p1.parent_id = p.id
    )The reason it's a guess is because you've really done nothing to outline WHY you should get the results you say you would like. The more time you spend creating a clear question, the less time you'll have to spend weeding through useless answers.
    Cheers,

  • Need help in SQL Select

    Hi All,
    I'm using the below script in conc.pgm to get some data
    Prompt ROllNO, DEPT, Amount, Store;
    SELECT ' '
    || ROLL_NO
    || ', '
    || DEPT
    || ', '
    || Amount
    ||', '
    || Store
    FROM XXX;
    And the output looks like this,
    ROll NO, DEPT, Amount, Store
    101,     ABC, 500,     XXX
    102,     ABC, -600,     YYY
    103,     ABC,     800,     ZZZ
    If you see in the second row, as the amount is negative, it is taking one extra space to accomodate the sign. Because of this, the other columns are affected.
    Now when i want an output someting like,
    ROll NO, DEPT, Amount, Store
    101,     ABC, 500,     XXX
    102,     ABC, -600,     YYY
    103,     ABC, 800,     ZZZ
    Means, i want the data to be aligned properly even if the selected column has more width.
    Any changes i need to do to the Query?
    Kindly provide some pointers
    Regards,
    Mohan

    Hi,
    The problem is with your data. For this type of query you will have to fix the length of every column..let say
    Dep Code is having values like 12,123,1234
    So, for this create your query like this...
    SELECT LPAD(DEP_CODE,(SELECT MAX(LENGTH(DEPT_CODE)) FROM XXX),' ') FROM XXXthrough this statement you can get the your desired result. use the same strategy for all columns by changing the column name.
    -Ammad

  • Sql select query problem

    hi friends,
    i've a view called "risk_efforts" with fields user_id,user_name,wknd_dt,week_day,prod_efforts,unprod_efforts.
    Name Type
    ROW_ID NUMBER
    USER_ID VARCHAR2(14)
    USER_NAME VARCHAR2(50)
    WKND_DT VARCHAR2(8)
    WEEK_DAY VARCHAR2(250)
    PROD_EFFORTS NUMBER
    UNPROD_EFFORTS NUMBER
    data is like this:
    when there is some data in prod_efforts, unprod_efforts will be null
    when there is some data in unprod_efforts, prod_efforts will be null
    for example:
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     null 3
    G666999     GTest     20100403     TUE     14     null
    now i want to combine these 2 rows into 1 row i.e o/p should be like this
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     14 3
    i've tried all combinations but couldn't get the query. Please help me with the exact SQL select query.
    thanks,
    Girish

    Welcome to the forum.
    First read this:
    Urgency in online postings
    Secondly, it's always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
    I'm just wagering a guess here but what about this:SELECT ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY
    , MAX(PROD_EFFORTS) AS PROD_EFFORTS
    , MAX(UNPROD_EFFORTS) AS UNPROD_EFFORTS
    FROM RISK_EFFORTS
    GROUP BY ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Save SQL select output as html page on another box.

    How can I save a simple sql select output on another server as a html page?

    Hi,
    You can use the Oracle product WebDB (Oracle Portal) to create reports in HTML over the DB (simplest way).
    Instead You can use SQL*Plus on the remote server (where You want to spool), enable the spool to file (using SPOOL) and create the select as
    SELECT 'html tags' &#0124; &#0124; field/s &#0124; &#0124; 'html tags'
    FROM your_table;Using this solution You have to manually "draw" the report.
    Hope this helps.
    Bye Max
    null

  • Oracle Select Max Date

    Hi,
    I need help with a Select statement that returns the most recent revision date from an Oracle database.
    This is my Select statement:
    SELECT
    STORE.ITEM.ID,
    STORE.ITEM.ITEM_NUMBER,
    STORE.ITEM.CATEGORY,
    STORE.ITEM.DESCRIPTION,
    STORE.REV.REV_NUMBER,
    STORE.REV.OBSOLETE_DATE,
    STORE.REV.RELEASE_DATE
    FROM
    STORE.ITEM,
    STORE.REV
    WHERE
    STORE.ITEM.ID = STORE.REV.ITEM AND
    (STORE.REV.OBSOLETE_DATE IS NULL) AND
    (STORE.ITEM.ITEM_NUMBER = '100.009')
    ORDER BY
    STORE.REV.RELEASE_DATE DESC
    The result is:
    4295110 100.009 207531 Widget001 07 NULL 10/20/2006 11:33:33 AM <-------------- Would like to have only this one item
    4295110 100.009 207531 Widget001 06 NULL 9/20/2005 7:57:26 AM
    4295110 100.009 207531 Widget001 05 NULL 11/13/2003 9:17:35 AM
    4295110 100.009 207531 Widget001 04 NULL 11/19/2001 12:10:25 PM
    4295110 100.009 207531 Widget001 03 NULL 3/21/2001 1:01:07 PM
    4295110 100.009 207531 Widget001 2 NULL 2/6/1999 10:55:19 AM
    Could someone please help me get the item with the most recent STORE.REV.RELEASE_DATE.
    Thanks.

    SQL> create table item (id,item_number,category,description)
      2  as
      3  select 4295110, '100.009', 207531, 'widget001' from dual
      4  /
    Tabel is aangemaakt.
    SQL> create table rev (item,rev_number,obsolete_date,release_date)
      2  as
      3  select 4295110, '07', null, to_date('10/20/2006 11:33:33 AM','mm/dd/yyyy hh:mi:ss am') from dual union all
      4  select 4295110, '06', null, to_date('09/20/2005 7:57:26 AM','mm/dd/yyyy hh:mi:ss am') from dual union all
      5  select 4295110, '05', null, to_date('11/13/2003 9:17:35 AM','mm/dd/yyyy hh:mi:ss am') from dual union all
      6  select 4295110, '04', null, to_date('11/19/2001 12:10:25 PM','mm/dd/yyyy hh:mi:ss am') from dual union all
      7  select 4295110, '03', null, to_date('3/21/2001 1:01:07 PM','mm/dd/yyyy hh:mi:ss am') from dual union all
      8  select 4295110, '2', null, to_date('2/6/1999 10:55:19 AM','mm/dd/yyyy hh:mi:ss am') from dual union all
      9  select 4295110, '1', sysdate, to_date('2/6/1998 10:55:19 AM','mm/dd/yyyy hh:mi:ss am') from dual
    10  /
    Tabel is aangemaakt.
    SQL> select item.id
      2       , item.item_number
      3       , item.category
      4       , item.description
      5       , max(rev_number) keep (dense_rank last order by release_date)
      6       , max(obsolete_date) keep (dense_rank last order by release_date)
      7       , max(release_date)
      8    from item
      9       , rev
    10   where item.id = rev.item
    11     and rev.obsolete_date is null
    12     and item.item_number = '100.009'
    13   group by item.id
    14       , item.item_number
    15       , item.category
    16       , item.description
    17  /
            ID ITEM_NU   CATEGORY DESCRIPTI MA MAX(OBSOLETE_DATE)K MAX(RELEASE_DATE)
       4295110 100.009     207531 widget001 07                     20-10-2006 11:33:33
    1 rij is geselecteerd.Regards,
    Rob.

  • 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

  • Problem with select max(FIELD)

    I have a table with the following fields:
    PARTID     ART_TYP     AEC     SERVICE     PLANT     STATUS
    4711     A     A     2     P     230
    4711     A     B     0     P     230
    4712     A     B     2     P     230
    4713     A     B     0     P     230
    I need a sqlscript where I get the records with MAX(SERVICE)
    In this example
    4711     A     A     2     P     230
    4712     A     B     2     P     230
    4713     A     B     0     P     230
    I tried this with:
    select distinct partid,
         art_typ,
         aec,
         max(service),
         plant,
         status
    from t_msltmp
    group by partid,art_typ,aec,plant,status
    But I get both records of partid=4711
    Can someone help me with this problem
    kind regards
    Menk Slot

    ROW_NUMBER() requires explicit ORDER BY clause in OVER:
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/functions105a.htm#86312
    SQL> select partid, art_typ, aec, mx, plant, status
      2  from(select partid,
      3                art_typ,
      4                aec,
      5                max(service) over (partition by partid) mx,
      6                row_number() over (partition by partid order by service desc) rn
      7                plant,
      8                status
      9         from t_t)
    10  where rn = 1
    11  /
        PARTID A A         MX P     STATUS
          4711 A A          2 P        230
          4712 A B          2 P        230
          4713 A B          0 P        230Rgds.
    P.S.
    Another way to get this (more tedoius):
    SQL> select partid,
      2  max(art_typ) keep (dense_rank first order by service desc) art_typ,
      3  max(aec) keep (dense_rank first order by service desc) aec,
      4  max(service) service,
      5  max(plant) keep (dense_rank first order by service desc) plant,
      6  max(status) keep (dense_rank first order by service desc) status
      7  from t_t
      8  group by partid
      9  /
        PARTID A A    SERVICE P     STATUS
          4711 A A          2 P        230
          4712 A B          2 P        230
          4713 A B          0 P        230Message was edited by:
    dnikiforov

  • 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
    ;

  • Pl/SQL Select Into

    Hello,
    is there a difference between the command 'select into' in Regions with 'pl/sql function returning Query' and 'Pl/sql amonymous block'.
    select MAX(maxgroups) into groupno from Table where trackid=:P_ITEM2 and col1=:P_ITEM2;
    This statement works only in the Region-'Pl/sql amonymous block.
    Can somebody help me please,
    I really can't find the reason!
    Moni

    Hi Marc,
    I' ve found out that the select statement works, the problem is that the items have no value.
    When I display the content of the item in the Region-Topic ‚Test – &P32_Item.’ it is displayed correctly.
    Maybe I’m calling the item in the pl/sql in a wrong way??
    lg
    Moni

Maybe you are looking for

  • Flash builder 4 - Image(s) Rotator3d

    Im looking for some inspiration too code a image gallery with 3d effects (Rotator3d sparkcontrol) in flash builder 4. Ive have a button which I want to execute the rotation between the images (mx:images), my question is how I shift betwwen images whe

  • MBpro to Older TV

    I have a macbook pro, with the DVI output on the side. I was wondering: 1) is there any kind of cord that would go to RCA video (JUST yellow, I don't have composite inputs) 2) is there a cord that'll work for the MBP like there is for ipod's that wil

  • Use "wlconfig"/"query" to get multiple mbeans and iterate

    The WebLogic documentation on the "wlconfig" Ant task shows how to use the "query" subelement to get an mbean based on the domain, type, and name. However, in the documentation, I see that the "name" attribute is optional. I tried writing a little te

  • Reviews shown on BlackBerry World App pages are inconsistent

    Hi, I noticed that most of the time, reviews are not shown on my app page.  First I thought it might be becuase of the settings(Device and Location) available at the top of the page. But no matter what I set, the reviews are not shown. And even if so

  • Re: Still can't sign into Digital Library.

    Hi, I am having the same problem. When I try to log into the digital library I get a message saying email and password don't match. I tried resetting my password, using different browsers, and clearing my browser cache, but have had no luck. Please h