locked
sum in group by RRS feed

  • Question

  • User-1155576298 posted

    kindly help

    m using sql server 2005 & want to display result as below

    colmn1        colmn2          colmn3         colmn4

    asd                001               500               ram

    dsa                002                1000            singh

    abc                003               400              kumar

    My data in table after using sql query is coming like:

    colmn1        colmn2          colmn3         colmn4

    asd                001               250               ram

    asd                001               250               ram

    dsa                002                600            singh

    dsa                002                400            singh

    abc                003              200              kumar

    abc                003               100            kumar

    abc                003              100              kumar

    thanks in advance

    Tuesday, September 20, 2016 10:23 AM

Answers

  • User753101303 posted

    Hi,

    For now it seems you want something such as :

    SLEECT column1,column2,SUM(column3) AS column3,column4
    FROM YourTable
    GROUP BY column1,column2,column4

    In short you group on  columns to create a row for each distinct column combination. You can select those columns as part of the result. For other columns you use an aggregation function to compute a single value for all rows in the group (such as a sum, max, min, avg etc...)

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 20, 2016 12:00 PM

All replies

  • User753101303 posted

    Hi,

    For now it seems you want something such as :

    SLEECT column1,column2,SUM(column3) AS column3,column4
    FROM YourTable
    GROUP BY column1,column2,column4

    In short you group on  columns to create a row for each distinct column combination. You can select those columns as part of the result. For other columns you use an aggregation function to compute a single value for all rows in the group (such as a sum, max, min, avg etc...)

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 20, 2016 12:00 PM
  • User-1155576298 posted

    Many Thanks

    Your example fulfilled my requirement

    once again thanks

    Tuesday, September 20, 2016 1:07 PM