Datagridview相同行的总和

时间:2014-01-10 16:37:33

标签: c# sql datagridview sum

我有一个基本上像这样的SQL表:

enter image description here

如您所见,有些数据使用相同的ProductID(1002和1004)。我希望此表格与相同ProductID的行进行求和并合并。

enter image description here

我正在使用c#和dataGridView。我们可以通过sql查询对这些值求和,然后将其加载到dataGridView上吗?或者我必须创建一个if - for etc ...语句来检查&求dataGridView行?

编辑:

对于大卫的回答:

   select * from tblOrderDetail where OrderID in 
   (select OrderID from tblOrders whereCustomerID = 231234)

 // Select * at start gets the ProductID and Quantity 

如何将解决方案添加到此?当我尝试几件事情时,我在使用“in”条款时遇到了错误。

1 个答案:

答案 0 :(得分:3)

SELECT   productID, SUM(Quantity) AS Quantity
FROM     myTable
GROUP BY productID
相关问题