嗨,我有一张表来跟踪几个员工做的几笔交易,这些是字段,同一个员工可以做几笔交易 我如何编写一个linq查询来获取包含每个员工的总交易详情的记录?
结果应具有唯一的员工ID,其总待处理金额和总收据金额
EmployeeID|PendingAmount|RecieptAmount
答案 0 :(得分:2)
按EmployeeID
分组记录,然后计算每个员工组所需的所有内容:
from e in db.Employess
group e by e.EmployeeID into g
select new {
EmployeeID = g.Key,
PendingAmount = g.Sum(x => x.PendingAmount), // total pending amount
RecieptAmount = g.Sum(x => x.RecieptAmount) // total reciept amount
}