帮助构建查询

时间:2010-07-01 09:11:25

标签: sql

我需要一些帮助来构建查询。 我有一个表“订单”有3个字段(IDorder,IDcostumer和金额),我正在尝试创建一个List,我为每个客户添加一行,总金额。

有人可以帮我构建此查询吗?

3 个答案:

答案 0 :(得分:2)

尝试以下方法:

SELECT IDCustomer, SUM(amount)
FROM Orders
GROUP BY IDCustomer

答案 1 :(得分:0)

SELECT sum(amount), IDcostumer FROM Orders GROUP BY IDcostumer

答案 2 :(得分:0)

感谢您的回答。通过您的查询,我尝试加入另一个表并使用linqer将其转换为LINQ。最终的代码是:

from c in contexto.Costumers join s in contexto.Sales on c.IDcostumer equals s.IDCostumer group new {c, s} by new { c.IDcostumer, c.name } into g select new { IDcostumer = (Int32?)g.Key.IDcostumer, g.Key.name, total = (Decimal?)g.Sum(p => p.s.total) }

不幸的是,我还不了解组的含义及其工作原理。 我会阅读一些文章来试图理解它。

谢谢;)

相关问题