SQL server 2000 Query

  • I have a table in the below mentioned format:

    COL1    COL2    COL3   COL4

    A         4          0        0

    B         5          0        0

    A         0          4        0

    C         1          0        0

    A         0          0        5

    B         0          7        0

    And I want the ouput in:

    COL1    COL2    COL3   COL4

    A         4          4        5

    B         5          7        0

    C         1          0        0

     

    Can anybody help me with the SQL query to get such an output????

  • SELECT COL1, MAX(COL2), MAX(COL3), MAX(COL4) FROM table GROUP BY COL1

    should do the trick.

    - James

    --
    James Moore
    Red Gate Software Ltd

  • Hi James,

    thanks a lot..I think that should work fine...

    But I still need to run that query to check the output.

     

    Thanks & Regards,

     

    Ankit

    Programmer Analyst

    CTS

  • it depends on what do you want

    this will also produce the desire output

    SELECT COL1, SUM(COL2), SUM(COL3), SUM(COL4) FROM table GROUP BY COL1

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply