×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

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?