Home Forums Tech Database SQL DB2 – How to add a column with row number

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3171
    VGlushkin
    Participant

    You have a fantastic SELECT statement.
    Now you need to add a new column with simple row count: 1, 2, 3 . . .

    Here is how you can do it on DB2 platform:

    SELECT ROW_NUMBER() OVER (), VLEDUS, VLEDBT, count(*) FROM
    F06116Z1 GROUP BY VLEDUS, VLEDBT 

    The result will look similar to this:

    ROW_NUMBER        User             Batch         COUNT ( * )
                       ID             Number                    
                 ---------------  ---------------               
             1     U11            00170835                   170
             2     U222           00170861                    54
             3     U33            00170865                    41
             4     U44            00170866                    11
             5     U55            00170863                     9

    Please. let me know, if this syntax works on different platforms.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.