我的列表包含factorId
,amount
,remain
列。
我需要计算按amount
remain
和factorId
列
答案 0 :(得分:2)
var groupedList = myList.GroupBy(i => i.factorId);
var results = groupedList.Select(g => new { SumAmount = g.Sum(i => i.Amount), SumRemains = g.Sum(i => i.Remains) });
答案 1 :(得分:2)
在一行中:
var groupedList = myList
.GroupBy(i => i.factorId)
.Select(g => new
{
FactorId = g.Key,
SumAmount = g.Sum(i => i.Amount),
SumRemains = g.Sum(i => i.Remains)
});