問題
使用 LINQ對DataTable做群組 並加總多個欄位
解決方法
Single Group
var result= from a in MyDataTable.AsEnumerable()Multiple Group
group a by a.Field<string>("resource_name")into g
select new
{
groupName = g.Key,
groupSum = g.Sum(r => r.Field<Decimal>("sum_field"))
};
var result= from a in MyDataTable.AsEnumerable()
group a by
new {groupName1= a.Field<string>("resource_name")
, groupName2= a.Field<int>("resource_age")} into g
select new
{
groupName = g.Key.groupName1,
groupAge = g.Key.groupName2,
groupSum = g.Sum(r => r.Field<Decimal>("sum_field"))
};
沒有留言:
張貼留言