嗨我有这个查询计算所有销售的产品,现在我想更改它,因此它计算特定客户的产品数量。有人可以帮我吗?表=表客户one2many交易one2many transactionitems many2one product many2one producttype
var query = from product in cse.tblTransactionItems
group product by product.tblProduct.Description into g
select new { ProductId = g.Key, totalUnitsSold = g.Count() };
答案 0 :(得分:0)
您可以考虑按多列进行分组。
var query = from product in cse.tblTransactionItems
group product by new
{
product.tblProduct.Description,
product.tblProduct.Customer // put the customer here.
} into g
select new
{
Product = g.Key.Description,
Customer = g.Key.Customer,
totalUnitsSold = g.Count()
};
这种方式totalUnitsSold
是特定客户和产品的总计。
注意:如果您的客户在另一张表中,您需要先加入。以上简单地假设客户是现有表格的一部分。