Getting the max number and show the row

hi
i have this table:
MyTbl
====
id | Name  |  Num
===========
1  | AAA    |   0
1  | BBB    |   1
1  | CCC    |   2
2  | DD     |   0
2  | EEE    |   1
3  | FFF    |   0
i need to show the max Num in row order by id
i need to see this:
MyTbl
====
id | Name  |  Num
===========
1  | CCC    |   2
2  | EEE    |   1
3  | FFF     |   0
 i need it on sqlight (or sql-server i think is same)
thanks

Here is an AdventureWorks example to get the maximum list price products for each color:
WITH CTE AS
(SELECT RNK=DENSE_RANK() OVER (PARTITION BY Color ORDER BY ListPrice DESC),
Color, ListPrice, ProductName=Name
FROM Production.Product WHERE ProductSubcategoryID > 0 AND Color is not null)
SELECT Color, ListPrice, ProductName FROM CTE
WHERE RNK = 1 ORDER BY Color, ProductName;
Black 3374.99 Mountain-100 Black, 38
Black 3374.99 Mountain-100 Black, 42
Black 3374.99 Mountain-100 Black, 44
Black 3374.99 Mountain-100 Black, 48
Blue 2384.07 Touring-1000 Blue, 46
Blue 2384.07 Touring-1000 Blue, 50
Blue 2384.07 Touring-1000 Blue, 54
Blue 2384.07 Touring-1000 Blue, 60
Grey 125.00 Touring-Panniers, Large
Multi 89.99 Men's Bib-Shorts, L
Multi 89.99 Men's Bib-Shorts, M
Multi 89.99 Men's Bib-Shorts, S
Red 3578.27 Road-150 Red, 44
Red 3578.27 Road-150 Red, 48
Red 3578.27 Road-150 Red, 52
Red 3578.27 Road-150 Red, 56
Red 3578.27 Road-150 Red, 62
Silver 3399.99 Mountain-100 Silver, 38
Silver 3399.99 Mountain-100 Silver, 42
Silver 3399.99 Mountain-100 Silver, 44
Silver 3399.99 Mountain-100 Silver, 48
Silver/Black 80.99 HL Mountain Pedal
Silver/Black 80.99 HL Road Pedal
Silver/Black 80.99 Touring Pedal
White 9.50 Mountain Bike Socks, L
White 9.50 Mountain Bike Socks, M
Yellow 2384.07 Touring-1000 Yellow, 46
Yellow 2384.07 Touring-1000 Yellow, 50
Yellow 2384.07 Touring-1000 Yellow, 54
Yellow 2384.07 Touring-1000 Yellow, 60
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

Similar Messages

  • How to get the Row and Column values in ALV (without using Objects)

    Hi All,
    I need to get the Row / Column when double click is used in ALV, I can use the double click event for this. However, I do not want to use the Object Oriented ALV. I want to implement the same functionality using general (using functions) ALV.
    Is there any way to get the row / column values for a Generia (non-OOPs) ALV report.
    Please help.
    Thanks,
    Vishal.

    Hello,
    The only think you have to do is to get the index where the user clicked, and then read the internal table you sent to the alv
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = 'prg_name'
          i_callback_pf_status_set = 'SET_PF_STATUS'
          i_callback_user_command  = 'USER_COMMAND' " this is to the click event!!
          i_callback_top_of_page   = 'TOP_OF_PAGE'
          is_layout                = alv_layout
          it_fieldcat              = alv_fieldcat
          i_save                   = 'A'
          it_events                = alv_events[]
        TABLES
          t_outtab                 = i_totmez.  ---> TOUR IT.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    " then....
    FORM user_commandUSING r_ucomm     TYPE sy-ucomm
                                    ls_selfield TYPE slis_selfield.
    " r_ucomm -> HAS THE STATUS
    " ls_selfield-tabindex  -> HAS THE SELECTED INDEX
    " THEN READ THE INTERNAL TABLE
    " HERE YOU WILL HAVE THE SELECTED ROW
    READ TABLE i_totmez INDEX ls_selfield-tabindex.
    ENDFORM.
    cheers,
    Gabriel P.

  • TableView -- get the row number of the top most current visible row

    Is there any way to get the row number of the top most visible row, and or bottom most visible row in TableView?

    If you already know the document's name, the sheet's name and the table's name, the easy way is :
    --Here you may replace the three values by the current ones
    set dName to 1
    set sName to 1
    set tName to 1
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
    tell first cell of the selection range to set {rowNum1, columnNum1} to {address of its row, address of its column}
    tell last cell of the selection range to set {rowNum2, columnNum2} to {address of its row, address of its column}
    end tell
    Yvan KOENIG (VALLAURIS, France) mercredi 9 février 2011 17:22:21

  • I can't get the row number of the current selection

    Hi all,
    How can I get the row number of a selection if I don't know the range selected? I need it to store in variable.
    I've tried in many ways, but unsuccesfully.
    Thank's in advance.

    If you already know the document's name, the sheet's name and the table's name, the easy way is :
    --Here you may replace the three values by the current ones
    set dName to 1
    set sName to 1
    set tName to 1
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
    tell first cell of the selection range to set {rowNum1, columnNum1} to {address of its row, address of its column}
    tell last cell of the selection range to set {rowNum2, columnNum2} to {address of its row, address of its column}
    end tell
    Yvan KOENIG (VALLAURIS, France) mercredi 9 février 2011 17:22:21

  • Latest update of Muse is not installing on several tries,installation gets stuck at 43% and shows '' waiting'' at the  ''Extracting''  stage for 7-8 hours after which it does not progress

    latest update of Muse is not installing on several tries,installation gets stuck at 43% and shows '' waiting'' at the  ''Extracting''  stage for 7-8 hours after which it does not progress.

    Refer to EX11....
    Creative Cloud Error Codes (WIP) | Mylenium's Error Code Database
    Mylenium

  • I purchased Adobe Acrobat XI Pro - Student and Teacher Edition but cannot activate it even after it has deactivated and replaced my old Acrobat 8. How do I get a serial number and activate the product?

    I purchased Adobe Acrobat XI Pro - Student and Teacher Edition but cannot activate it even after it has deactivated and replaced my old Acrobat 8. How do I get a serial number and activate the product?

    I have the same  problem. Have paid. Messages say I have downloaded it but the file is inaccessible apparently download is somewhere on my hard disk. How do I find it?? Is there not help at an Adobe phone service. If so what is the number to call??
    Roger Broughton

  • How to get the row number

    Hi list,
    does any one know how I can get the row number the same as what I have in column rowno?
    thanks
    Arvin
    REATE   TABLE dbo.temptable
    ( y int  NOT NULL,
      e int not null,
      c int not null,
      rowno int not null)
    /* insert values  */
    INSERT INTO dbo.temptable(y,e,c,rowno ) VALUES
    (1,1,1,1),
    (1,1,2,1),
    (1,1,3,1),
    (1,20,1,2),
    (1,20,2,2),
    (1,20,3,2),
    (1,3,1,3),
    (1,3,1,3),
    (2,1,1,1),
    (2,1,1,1),
    (2,2,1,2),
    (2,2,1,2);

    You may update your rownumber column with Column "e".
    But why do you duplicate your data? May be there is no particular reason, you may be wasting space for it
    Try the below:
    CREATE TABLE dbo.temptable
    ( y int NOT NULL,
    e int not null,
    c int not null,
    ronum int null)
    INSERT INTO dbo.temptable(y,e,c ) VALUES
    (1,1,1),
    (1,1,2),
    (1,1,3),
    (1,20,1),
    (1,20,2)
    select * from temptable
    update dbo.temptable Set ronum=e
    Select * From dbo.temptable
    DRop table dbo.temptable

  • TS1367 Hallo,I have an IMAC 21.5. which does not start.When i press the power button i hear only beep with an interval of 4-5 seconds.Some times when i take off the RAMS and put them again then get a white screen and shows that i have to insert a bootable

    Hallo ,I have an IMAC 21.5. which does not start.When i press the power button i hear only beep with an interval of 4-5 seconds.Some times when i take off the RAMS and put them again then get a white screen and shows that i have to insert a bootable device.Then i bought OSX mountainlion on line and wrote it on a DVD and tried with a USB key board to start the DVD.But does not work.Please help me to get this imac work.
    Thankyou in advance  for your help.
    Terrence

    Hey terremo,
    Thanks for the question. From the information you provided, it sounds like the iMac is successfully turning on, however video is not displayed. These symptoms can usually be isolated further by the troubleshooting steps in this article:
    Apple computers: Troubleshooting issues with video on internal or external displays
    http://support.apple.com/kb/HT1573
    Thanks,
    Matt M.

  • How to get the rows from a table having some column has any letter

    Hi All,
    suppose i have a table having columns id(number), code(varchar).
    code has alphanumeric characters (ex. ABC123, 67B56 etc).
    some codes are only numbers (2344, 7898 etc).
    how can i get the rows which have alphabets in the code.
    ex:
    id code
    1 AB45
    2 456
    3 890
    4 67B7
    how can i write a query such that it should give me the ids 1 and 4 (as they have alphabets in code)
    thanks in advance to all

    Thanks to one and all.
    i am gettig my required output.
    But i have a doubt in the operator.
    If i add or remove '[]' in the operator, i am getting different ouputs.
    There is a count difference in the result of the operators used.
    REGEXP_LIKE(<column>,'[[:lower:]]')
    REGEXP_LIKE(<column>,'[[[:lower:]]]')
    REGEXP_LIKE(<column>,'[:lower:]')
    Can anybody please explain what is the difference in using '[]', in the operator?
    What is the correct syntax, whether i have to use two '[]'s or one '[]'.
    Also, can i use REGEXP_LIKE() in oracle 8i version.( I am unable to use the operator in 8i)?
    Any query to get the required output in 8i version?
    Thanks in advance to all.

  • Get the # row

    Hi there,
    if Im in the form "41" (Batch Setup) in the grid or matrix id "35" (Rows from documents) and let say I got 3 lines and I've highlighted the second one, how can get the row nr, tipically the value under the column 0 the one with column title "#"?
    There is any method to retrive that value?
    Thank you
    Roberto

    you want to get the selected row no
    you can try this
    for int i=1 to oMatrix.RowCount
    if oMatrix.IsrowSelected(i)==true
    messageBox.Show(i);
    You can Write your code here

  • How to get the row Count of a ResultSet

    How to get the row Count of a ResultSet

    Hi
    I'v tried rennie1's way ,but I only get zero,my code is:
    rs.executeQuery("select count(*) from t_test");
    if (rs.next()) int rowCount=rs.getInt(1);
    I also tried barni's way ,but the method rs.last() and rs.beforeFirst() throw a same Exception
    I tried another way,the code is:
    while rs.next(){
    // Do nothing ,just move the cursour to the last row
    int rowCount=rs.getRow()
    However,the rowCount still equal zero
    Any help would be greatly apprecite!
    note:
    I get connection by DataSource's JNDI name from client, the Server is Weblogic Server 6, the DBMS is Oracle.

  • Get the rows in the same order in which it has been inserted.

    Hi,
    I have a table with four columns(All varchars)...and there are no primary keys
    i have inserted 15 rows where col1="xyz"
    Now while retrieving the same...i dont get the same in the order i ahve inserted..
    What is the way to get the rows in the same order in which it has been inserted..?
    Regards

    I have a table with four columns(All varchars)...and
    there are no primary keys
    i have inserted 15 rows where col1="xyz"
    Now while retrieving the same...i dont get the same
    in the order i ahve inserted..
    What is the way to get the rows in the same order in
    which it has been inserted..?
    RegardsWhy? What is your business case behind this?
    In my experience an "order by" is used way too much without any real need to do it. Are your users interested to know in what order a few records from two years ago have been inserted? What about updates since that time?

  • RowDisclosureListener af:table - Getting the Row in the Listener Method

    Hi,
    I am bit new to the adf. I have a requirement and it is as below.
    (1) I am using only ADF faces, Not with Business Components. All values/ list comes from a ManagedBean
    (2) I am displaying List of Employees in an <af:table>
    (3) I have something as detailStamp
    (4) For Some reason I have do some business logic (set some flag in the EmployeeBean) whenever it is Disclosed / selected
    (5) One portion of it is done and that is when the row is selected.
    (6) I dont know how to get the Row bean (Employee Bean) when it is disclosed
    Any Ideas how to do that?
    The code which I wrote to get the Employee Bean when it is selected (selectionListener) is as below and I want to do that in my RowDisclosureListener
    //This Works fine//
    public void messageSelectionListener(SelectionEvent selectionEvent) {
    System.out.println("Entering messageSelectionListener : " + selectionEvent.getComponent().getClientId());
    // set the selected message flag
    if (((Employee)getSearchResultTable().getSelectedRowData()).isSelectedForView()) {
    ((Employee)getSearchResultTable().getSelectedRowData()).setSelectedForView(false);
    TableUtils.closeRow(selectionEvent);
    } else {
    ((Employee)getSearchResultTable().getSelectedRowData()).setSelectedForView(true);
    TableUtils.discloseRow(selectionEvent);
    // update table in UI
    refreshTable();
    //How to do it in RowDisclosureListener
    public void messageDisclosureListener(RowDisclosureEvent rowDisclosureEvent) {
    System.out.println("Entering messageDisclosureListener: " + rowDisclosureEvent.getComponent().getClientId());
    RichTable table = (RichTable)rowDisclosureEvent.getSource();
    //How to get the Employee Bean here?
    refreshTable();
    Thanks in Advance.

    Krishna,
    You code did the trick. But how does M_TABLES gets updated with the record count?
    Wouldn't it be advisable to get the record count from the table itself rather than M_TABLES?
    Thanks.

  • Problem getting the row  element

    hi
        i have a scenario where  i have  filtered data from
       3 listboxes  and  populated the data in the  table .
      now  the table contains  about  10  rows  .
      now  i need to select a particular  row  in the  table 
       and  catch the particular row data  of the table .
    n is size of the table .     
    for(int i=0;i<n;i++)
                           if(wdContext.nodeIt_Car_Data_t().isSelected(i) {
    String model=wdContext.nodeIt_Car_Data_t().currentIt_Car_Data_tElement().getP_Model();
    String trim=wdContext.nodeIt_Car_Data().currentIt_Car_DataElement().getP_Trim();
    but  iam not able get the row data in the string where i am catching in
      it_car_data_t  is the  table node .  
    model  and  trim  are table elements . 
    how can i solve this ?

    hi
    thanks  for the reply  ,  but  the same issue .
    problem here is  when i am filtering the data for the Itemlistbox
              i am catching filtered data in the String
      and  then setting it to a Structue IT_CAR  as 
    Z_CAR_DATA car= new Z_CAR_DATA()
    car.setMake(make)
    next   adding this car to the   RFC 
    wdcontext.currentRFC.modelobject.additcar(car).
    not  i will get the filtered ddata in table . along with  some 
    extra data in the  table .
    now  i need to catch the row  data  then  again set it
    IT_CAR (which i have done above )
    data i am setting is not  going to IT_CAR structure  .
    because  after i get the data in the IT_CAR strucure i can
    data this to the RFC .
        can  any one help me out with this issue .
      i need to  get the  row of the table  and then  set it 
    to a structure  which  iam not able to .

  • How can you get the Row at the mouse pointer??

    I got a JTable displaying info. I want to get the Index of the Row I click on.
    I can getX(), getY() with a MouseListener, but I am unable to get the row index related to these coordinates.
    Thanks!
    Olivier

    Sorry.
    That's ridiculous. I just found the rowAtPoint(Point point) method in JTable.
    Solved!!

Maybe you are looking for