如何在sql中求和多行 [英] How to Sum multiple lines in sql
本文介绍了如何在sql中求和多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多行数据共享同一个公司 ID.
I have multiple lines of data all sharing the same Company id.
有没有办法使用 SQL Server Management Studio 2005 对所有金额进行求和",以便为我提供每个公司 ID 的一行数据?
Is there a way to 'sum' all the amounts to give me one line of data per company id using SQL Server Management Studio 2005?
例如我目前有以下数据......
For example I currently have the below data......
Company_Name Company_ID Amount
Company 6 10024 120
Company 6 10024 569
Company 6 10024 53
Company 6 10024 100
Company 6 10024 564
Company 7 10638 9500
Company 7 10638 105
Company 7 10638 624
我想尝试并得到的是......
What i would like to try and get is.......
Company_ Name Company_ID Amount
Company 6 10024 1406
Company 7 10638 10229
有没有办法做到这一点?
Is there a way of doing this?
任何为我指明正确方向的建议都会很棒.
Any advice pointing me the right way would be great.
谢谢,
推荐答案
SELECT Company_Name, Company_ID, SUM(Amount)
FROM TableName GROUP BY Company_Name, Company_ID
这篇关于如何在sql中求和多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文