2014-02-10 49 views

回答

1

組行由ZONE字段的值,然後計算組所有行的字段的總和(分組鍵將區名):

var query = from r in table.AsEnumerable() 
      group r by r.Field<string>("ZONE") into g 
      select new { 
       Zone = g.Key, 
       TotalValue = g.Sum(r => r.Field<int>("Value")) 
      }; 
0
var results = (from r in dt.AsEnumerable() 
       group r by r.Field<string>("ZONE") into g 
       select new { 
        Zone = g.Key, 
        Sum = g.Sum(x => x.Field<int>("Value")) 
       }) 

var results = dt.AsEnumerable() 
       .GroupBy(
        x = > x.Field<string>("ZONE"), 
        (k, g) => new { ZONE = k, Sum = g.Sum(x => x.Field<int>("VALUE")) });