×

Loading...
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!

sql query question: how to sum 1 column?

I'm a newbie on sql query, please throw some light on following :
Table like:
col1 col2 col3 col4
1 10.00 abc company
2 20.00 def company
2 30.00 def company
3 40.00 ghi company

Result should be like:
col1 col2 col3 col4
1 10.00 abc company
2 50.00 def company
3 40.00 ghi company

thanks.
Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / sql query question: how to sum 1 column?
    I'm a newbie on sql query, please throw some light on following :
    Table like:
    col1 col2 col3 col4
    1 10.00 abc company
    2 20.00 def company
    2 30.00 def company
    3 40.00 ghi company

    Result should be like:
    col1 col2 col3 col4
    1 10.00 abc company
    2 50.00 def company
    3 40.00 ghi company

    thanks.
    • select col1, sum(col2), col3, col4 from table_name group by col1, col3, col4
      • thanks. it works
      • If I change the contents of col4 to company1, comany2,company3,company4. then I still wanna sum(col2) by col1 with any company in the same row, is it hard to realize? thanks again
        • try: select col1, sum(col2), col3, min(col4) from table_name group by col1, col3
          • thanks. it works
    • we are under an emergency situation so i did not read your post, but will "sum" do?