How to find max based on 2 columns.

Hi I have a table where I have two numeric fields (date and time) )(thouse field are not date time format but numeric)
Column A represents date and column B represent time.
How would I find max value of column A and with results for A find Max for B.
example
A - - - - - - - - - -B
101010 - - - - - 202020
101011 - - - - - 202021
101012 - - - - - 202021
101010 - - - - - 202022
101012 - - - - - 202020
What I looking for is
A - - - - - - - - - - B
101012 - - - - - 202021
Thanks

You can try one of the following...
sql> select * from temp;
         A          B
    101010     202020
    101011     202021
    101012     202021
    101010     202022
    101012     202020
  1  select a,b from (
  2     select a,
  3            b,
  4            rank () over (order by a desc, b desc) rnk
  5       from temp
  6* ) where rnk = 1
sql> /
         A          B
    101012     202021
  1  select a,b from (
  2    select a,b from temp
  3       order by a desc, b desc
  4* ) where rownum = 1
sql> /
         A          B
    101012     202021Please try to provide create table statements and insert data scripts instead of "select * from table".
It helps creating your case easier.

Similar Messages

  • How  to   find  article based  support  for  ipad  or  technical notes

    how  to   find  article based  support  for  ipad  or  technical notes

    The problem comes from VBUK/VBUP which are the control tables for most of SD tables (from VBAK/P to LIKP/PS and VBRK/P) and manage uniqueness of id in the module (and stores statuses). Even item tables don't refer to their header but both refer to the same VBUK record.
    e.g.
    LIPS : VBELN/POSNR -> VBUK/VBUP -> but you will only find LIKP/PS itself and no record in VBAK/VBAP
    LIPS : VBELV/POSNV -> VBUK/VBUP -> you should find VBAK/VBAP
    The table VBFA "Sales Document Flow" manages the relations from/to between two different SD documents which exist in VBUL/P and in only one other table depending on type of document. (Also note that the exact relationship may sometimes be modified to some extent by Customizing SD.)
    As Katan wrote, look for views defined in ddic, look also at logical databases (SE36) like VLV.
    You can also find valuable information in OSS notes/documents like 185530 - Performance: Customer developments in SD.
    Regards,
    Raymond

  • How to find max(time) from table using group by

    how to find max(time) from table using group by
    select var max(time)
              from table
              into (var1, time1)
               where .....
                 group by var.
    it is fetching record which is top in table.
    if u can help?
    regards.

    No this will fetch the maximum time from teh table.
    select var max(time)
    from table xxxx
    into (var1, time1)
    where .....
    group by var.
    Refer this code
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.

  • How to find the sum of a column

    I need to find the sum of a column and use it in a different column. The following is the example.
    Column names: Feedback(Good, Avg, Poor), Count(no of good, no of avg, no of poor) and %age(Feedback/sum(feedback))
    I want to find the sum in Java class and also calculate the last column in java class.
    Please tell me some way to do it.

    oh.. ok ..thanks for letting me know.. i will formulate the question in a proper way:
    This is what my UI should look like:
    Rating Count Percent
    Excellent 2 20
    Good 6 60
    Poor 1 10
    Bad 1 10
    Now i have the following columns in the data base:
    Meaning and feedback_rating.
    So the following SQL Query:
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    will give me the result as
    rating counted
    Excellent 2
    Good 6
    Poor 1
    Bad 1
    Now I want a third column as percentage : Earlier we were doing this calculation in the sql query itself, so the query was like
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted,
    sum(decode(bcpi.feedback_rating, null, 0, 1))/(max (select count (*) from cmp_cwb_person_info bcpi ,
    hr_lookups hrl )) percent
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    Hence the third column (percent) was calculated in the sql query itself.
    But now i feel that the performance of the query could be improved if we get the first two columns from the database and the calculate the third column programatically in the java code.
    So this is what I want to know. How can i do that?

  • How to find default value of a column ?

    hi , alok again,
    i have to find default value of a column.
    Acutally i have found , column's max width, its nullability, precision, scale, type, but NOT default value.
    I will have to use the default value and nullability while validating user's input.
    ResultSetMetaData doesnot contain any method any such method...
    Pls help,
    how can i do so.
    Any idea will be highly appreciated.
    Thanks in adv.
    Alok

    Hi,
    After you get the resultset from DatabaseMetaData.getColumns() as shown by sudha_mp you can use the following columns names to retrieve metadata information:
    Each column description has the following columns:
    TABLE_CAT String => table catalog (may be null)
    TABLE_SCHEM String => table schema (may be null)
    TABLE_NAME String => table name
    COLUMN_NAME String => column name
    DATA_TYPE int => SQL type from java.sql.Types
    TYPE_NAME String => Data source dependent type name, for a UDT the type name is fully qualified
    COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
    BUFFER_LENGTH is not used.
    DECIMAL_DIGITS int => the number of fractional digits
    NUM_PREC_RADIX int => Radix (typically either 10 or 2)
    NULLABLE int => is NULL allowed.
    columnNoNulls - might not allow NULL values
    columnNullable - definitely allows NULL values
    columnNullableUnknown - nullability unknown
    REMARKS String => comment describing column (may be null)
    COLUMN_DEF String => default value (may be null)
    SQL_DATA_TYPE int => unused
    SQL_DATETIME_SUB int => unused
    CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
    ORDINAL_POSITION int => index of column in table (starting at 1)
    IS_NULLABLE String => "NO" means column definitely does not allow NULL values; "YES" means the column might allow NULL values. An empty string means nobody knows.
    SCOPE_CATLOG String => catalog of table that is the scope of a reference attribute (null if DATA_TYPE isn't REF)
    SCOPE_SCHEMA String => schema of table that is the scope of a reference attribute (null if the DATA_TYPE isn't REF)
    SCOPE_TABLE String => table name that this the scope of a reference attribure (null if the DATA_TYPE isn't REF)
    SOURCE_DATA_TYPE short => source type of a distinct type or user-generated Ref type, SQL type from java.sql.Types (null if DATA_TYPE isn't DISTINCT or user-generated REF)
    Regards,
    bazooka

  • How to get max value of a column in VO?

    Hi ,
    i need to find the max value of a column named insured value in VO.
    Please help!!

    Hi,
    If this value is cuming from the Query then u can easily go for MAX function. If its a user enterable value then u need to iterate through all the rows for that column to find the max of them.
    Let me know.
    Regards,
    Gyan

  • How to find the new tables and columns in a schema

    hi..good morning to all...
    I have a schema ABC which owns some objects.
    Now some days before I have made another schema XYZ which was a replica of ABC schema.
    between these days some new tables, new columns in the existing tables(with or without default value), comments on the columns are being added in the new schema i.e XYZ schema.
    Now I have to find the extra things which are present in the new schema. I need to find the new tables, new columns in hte existing tables, their default values and descriptions of those.
    Can u plss help me how can I find it?
    I am guessing that I have to write a SQL query with a minus clause but I am not able to write it and also dont know where should I execute it.
    plss help. thanks in advance.

    And moreover, when I am executing the query to get the desired result, then it is throwing "illegal use of long datatype" error and pointing to the b.data_default area of my query..
    select a.table_name, a.column_name, b.data_default, a.comments from all_col_comments a, dba_tab_columns b
    where a.TABLE_NAME=b.TABLE_NAME
    and a.OWNER=b.OWNER
    and a.OWNER=XYZ
    minus
    select c.table_name, c.column_name, d.data_default, c.comments from all_col_comments c, dba_tab_columns d
    where c.TABLE_NAME=d.TABLE_NAME
    and c.OWNER=d.OWNER
    and c.OWNER='ABC'
    order by 1, 2;
    plss help...

  • How to find the difference of two columns in deski

    Hi Everyone,
    I have a deski report which is build from a single query. The report contains two tables.
    Table-1:MTK Loc
               MTKnet
    Table-2:WTK Loc
                WTKnet
    Now i need to find the difference of the columns WTKnet and MTKnet.
    These two are report level variables.Their definitins are as  below:
    MTKnet:=Sum((<Fees Collected by Per Collected>) In Body) ForEach <vMTKLocation>
    WTKnet:=Sum((<Fees Collected by Per Collected>) In Body) ForEach <vWTKLocation>
    Where <Fees Collected by Per Collected> is universe variable.
    Please help...
    Thanks in Advance......

    Hi Bol,
    As I understand you are taking MTK_Loc and WTK_Loc together in  the report which have common values under Fees Collected by Per Collected  column.
    Please follow the steps mentioned below:
    1.  Calculate the Variables MTK_Net as
           =Sum(<Fees>) IN <MTK_Loc>
    2.  Calculate the Variables WTK_Net as
           =Sum(<Fees>) IN <WTK_Loc>
    3. You will get the values based on the Locations MTK_Loc and WTK_Loc .
    You are using combination of values for MTK_Loc and WTK_Loc hence you will get the variable values in combination.
    Insert new column right to the WTK_Net and  write the formula name it Variance.
    =<MTK_Net>- <WTK_Net>
    The values look like :
    MTK_Loc      WTK_Loc             MTK_Net                 WTK_Net             Variance
    Chicago           Chicago                16,696,274.43      157,168.26            16,539,106.17
    Chicago           Madison               16,696,274.43       274,396.12            16,421,878.31
    Chicago           Milvaki                 16,696,274.43       16,622,870.97       73,403.46
    Chicago           Pennsylvania        16,696,274.43        4,299.35               16,691,975.08
    Chicago           Waukesha             16,696,274.43        22,067.08             16,674,207.35
    Here you will see values for MTK_Net are repeated because these are based on the MTK_Loc which is same for all rows i.e. Chicago , same is the case with remaining values of MTK_Loc.
    We can not calculate variabnce based on the values like Canada,Pennsylvania for all values as these values come in combination of each other and as these are all connected columns WEBI groups  Measure data based on the Dimension  and variable columns associated with it.
    MTK_Loc   WTK_Loc          MTK_Net         WTK_Net          Variance.
    Chicago        Chicago           16696274.43        157168.26           16539106.17
    However you can compare the values based on the values  as :
    1. Drag and Drop MTK_Loc and MTK_Loc separately on the report.
    2. Drag and Drop WTK_Loc and WTK_Loc separately and put it on the report, Connect it to the columns MTK_Loc and MTK_Loc columns already dragged. Then you can compare the values
    MTK_Loc                MTK_Net                         WTK_LOC                    WTK_Net
    Chicago                    16,696,274.43                 Chicago                       157,168.26
    Madison                   315,705.91                       Madison                      274,396.12
    Manitowoc              362,632.50                        Manitowoc                  359,978.50
    Milvaki                    54,172.84                          Milvaki                       16,622,870.97
    Pennsylvania             2,966.56                           Pennsylvania               4,299.35
    Waukesha                 9,028.03                          Waukesha                      22,067.08
    Here I unchecked the option avoid duplicate row aggregation (select table-> format table) thatu2019s why it is showing all values as a  sum of all MTK_Net and WTK_Net values corresponding to Location values..
    Here we are using MTK_Loc and WTK_Loc separately and not connected because though values seems same but they are used in combination ( Chicago, Pennsylvania)  in 2 separate tables in DB hence we canu2019t synchronize them by liking these 2 location columns using 2 data providers.
    I Hope this is what you want....
    Thanks....
    Pratik

  • How to find out the tablename and column name

    Hi,
    I have inserted a value (say 'I am here') in a table. but i don't know which is getting inserted this value.
    Now i want to know which table and colums has this value (I am here). How to find out as without knowing the table name.
    Is there any option to get the tablename and colum??.
    Please help me.
    thanks.

    Does nobody document their code anymore?
    See my response Re: How to find out a tablename for one possible solution.
    HTH
    John

  • Query help needed in finding max value between two columns

    I have a table as follows:
    -- INSERTING into TESTTABLE
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('A','4.5','AA',0.3,'AB',5.5);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('B','1','BB',2.5,'BC',6.9);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('C','2.6','CC',3.3,'CD',1.4);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('D','1.8','DD',2.9,'DE',1.2);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('E','6.8','EE',4.8,'EF',9.6);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('F','2.0','FF',6.34,'FG',3.9);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('G','1.7','GG',3.6,'GH',5.8);
    I want to get results as follows:
    COLA COL2 MaxCol MaxColVal
    A 4.5 AB 5.5
    B 1 BC 6.9
    C 2.6 CC 3.3
    D 1.8 DD 2.9
    E 6.8 EF 9.6
    F 2.0 FF 6.34
    G 1.7 GH  5.8I want to get the max value of either of the columns COLD or COLF.. Whichever column has got max value, then the corresponding value of COLC and COLE should be returned..
    For eg., in first row, COLF has higher value than COLD.. ie., COLF = 5.5 > COLD = 0.3, so for row1, i want the result as MaxCol is AB and MaxColvalue is 5.5..
    Similarly for third row, COLD =3.3 > COLF=1.4, so for 3rd row, i want the result as MaxCol is CC and MaxColvalue is 3.3
    How is it possible to do this in a qery? Any help.. please..

    SQL> select cola
      2       , col2
      3       , case greatest(cold,colf)
      4         when cold then colc
      5         else cole
      6         end maxcol
      7       , greatest(cold,colf) maxcolval
      8    from testtable
      9  /
    C COL MA  MAXCOLVAL
    A 4.5 AB        5,5
    B 1   BC        6,9
    C 2.6 CC        3,3
    D 1.8 DD        2,9
    E 6.8 EF        9,6
    F 2.0 FF       6,34
    G 1.7 GH        5,8
    7 rijen zijn geselecteerd.Regards,
    Rob.

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

  • How to find apostrophes in a VARCHAR2 column

    I have a value "GOT UP LATE - DIDN'T HAVE TIME"
    stored in varchar2 field of my table through Oracle forms. I want to check whether the values stored in this column have apostrophes or not (e.g. as in DIDN'T). Could any body please let me know how to do this.
    Rajeev
    [email protected]

    You can use the INSTR function
    INSTR(string, set[,start[,occurence]])
    INSTR('abcdecg', 'c') would return 3 since the 1st occurence of 'c' is at position 3 in the string.
    INSTR('abcdecg', 'c', 1, 2) would return 6 since the 2nd occurence of 'c' is at position 6 in the string.
    INSTR('abcdecg', 'c', 4) would return 6 since the 1st occurence of 'c', starting at position 4, is at position 6 in the string.
    Good luck.

  • How to find max audio peak of combined audio tracks with effects applied?

    Hello all,
    I am working in PPro CS5.5.
    Often when I am working on a timeline I have two audio tracks of the same songs, one from the camera and one from a separate sound recorder, synced on the timeline so they combine into one signal. Applied to these tracks I might have an E.Q. effect or highpass/lowpass filter. Now I know that the max peak of each track or individual clips is easy to find using the 'Audio Gain' menu item, what I am hoping for is the equivalent of that menu item but related to the final output after the two tracks signal has been added together and effects have been all been applied? It is a very laborious task to have to listen through the whole timeline to discover if the output is going over 0db, if there was a way I could locate on the timeline where the max output is, that would definitely solve the problem.
    Finding the way to do this would save literally hours per project! It's the one thing that makes me inwardly groan when I have to effect the output volume, which I have to do most of the time.
    Hopefully,
    Peter.

    I have found audio to be more difficult to learn than video. Audio has so much more subtlety, where perceptions don't always equate to what seems obvious. With multiple tracks adding together things get very complex very fast and peak amplitude has very little relationship to volume. When you compress a waveform the volume can be increased! Who'd have thunk it? Then you have S/N ratios and harmonics, soft clipping and hard clipping... Which brings me to the option on the Dynamics Effect called Soft Clip that is a smoother kind of limiter.
    It's amazing where a simple one line suggestion can lead you; having worked a bit more with the dynamics 'effect' I am deciding that I like it a lot. The automation is not absolute but it broadens the tolerances I can work within. Very liberating!

  • How to find the duplicate entries in column

    clolum name descripitoin ex:
    CLIENT_NAME | Last Name | First Name | Middle Name |suffix | Tendulkar Sachin Ramesh Jr.Sachin
    | | Sachin Tendulkar Ramesh Jr.Sachin
    | | Ramesh Sachin Tendulkar Jr.Sachin
    PANno | no | AUBIU1966E
    Address | Address of clint | Any address
    Insert multiple records as per the e.g. shown in table. Write a oracle procedure in database schema to input the string and identify the possible duplicates from above table.

    942919 wrote:
    HI
    but clint name is like
    CLINT_NAME
    Sachin Tendulkar Ramesh
    Sachin Ramesh Tendulkar
    Tendulkar Sachin Ramesh
    in this senario clint name column show diffrent names
    your query is not working
    above three entries are same we need to find aboue three entries are duplicate1. Have one other column called Name2 in the table
    2. scan the table and run the "combined" (means you combined every row from below separated by a space) the below output into name2 column
    with t as (
         select 'Sachin Tendulkar Ramesh' col from dual
         select TRIM(substr (splitted,
              instr (splitted, ' ', 1, level ) + 1,
              instr (splitted, ' ', 1, level+1) - instr (splitted, ' ', 1, level) -1 )) as ret_row
         from (select ' '||col||' ' splitted
         from t)
         connect by level <= length(splitted)-length(replace(splitted,' ',''))+1
         and instr (splitted, ' ', 1, level+1) - instr (splitted, ' ', 1, level) -1 > 0 order by 1;
    3. now run this
    select name2,count(*)
    the same like above but group by name2, then you will see it

  • SSRS Reports level how to find out All tables names & columns list to display dynamically SQL Query????

    Hi Team,
    I Have one requirement,In SSRS Reporsitory 3000 reports are available.
    My end user requirement All 3000 reports are used Table names & columns list of each wise to display single table or single result set.
    I find out all 3000 reports details are diplayed single results set like
    Report Id,Path,Dataset,Source Query Text,Datasource
    In Source Query Text  column level All reports Queries are available but I want Each Report wise Table name & columns List.If any solution Please share me.
    Regards
    Rama

    Hi Ramakoteswara,
    According your description, you want to show used tables and columns of each report, and display is into a single result set. Right?
    In this scenario, we don't know where to find a column contains the Source Query Text. With my understanding, in Reporting Services, we have Catalog table in ReportServer DataBase, it has a column called Content stores the report code (.xml). In the
    code we can find the Query and Fields. Then you need to use VB/C# code to parse each .xml code of each report and fetch out the table name and columns. We do not support writing any queries against SSRS DataBase or parsing data records in any
    table.
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

Maybe you are looking for

  • Missing right parenthesis error when querying using a list of values

    Would anyone know why this statement gives the ORA-00907: missing right parenthesis error..? SELECT FIELD_X FROM TABLE_Y WHERE FIELD_X IN ( 'AJD' 'RED' 'ADF' 'MOI' The reason why I wanted the AJD, RED, ADF, etc values on top of each other is because

  • Creating a new Master Page for new SharePoint 365 Environment

    Hello, If you create a new Master Page for your 365 site collection should all the Promoted Links, List Headings, etc. (standard items that are in the OOO SP Master Page) still remain the 'Blue SP Color' or are you able to change these items in the M

  • Use check box for report and form

    Hi Expert, I try to use check box to select multiple rows in a report and then click on a button to go to a form on another page to choose some values from the form and then do a mass update for records selected in reports. I read the "How to Work wi

  • How to use applescript to enter a contact in Microsoft Word

    I am new to applescript, but I am trying to find a good way to use applescript in Microsoft Word along with Dragon Dictate for Mac to automate writing a letter. Dictate allows me to use applescript upon saying a command. What I would like to do is to

  • Terminating JVM

    Hi, Im not sure if what I am thinking can be done, please bear with me... I have two Java program A and B (I would rather not change the source for B as its a proven app), program A instantiates B through using Runtime.exec(). However program B also