1

我的表看起来像 -
   Area MaxRate MinRate Quarter year
    过境 1000 800 1 2013
    过境 900 700 2 2013
    过境 800 600 3 2013
过境 700 500 4 2013 过境 600 500 1 2012 过境 550 450 2 2012 过境 500 400 3 2012
过境 450 350 4 2012 内降 2000 1500 1 2013 内降 1800 1500 2 2013

 I want max and min rates for the particular area in current year as -

 **Area    MaxRate  MinRate       year**
 crossing  1000     500           2013

请帮我在 LINQ-lambda 表示法中找到查询

4

1 回答 1

2

您可以使用它GroupBy来执行此操作:

var results = table.GroupBy(row => new { Area = row.Area, Year = row.year })
                   .Select(g => new { 
                                       Area = g.Key.Area, 
                                       MaxRate = g.Max(i => i.MaxRate),
                                       MinRate = g.Min(i => i.MinRate),
                                       Year = g.Key.Year
                                    });
于 2013-04-15T18:10:21.720 回答