1
votes

my table looks like-
  Area    MaxRate  MinRate Quarter year
    crossing  1000     800     1       2013
    crossing  900      700     2       2013
    crossing  800      600     3       2013
crossing 700 500 4 2013 crossing 600 500 1 2012 crossing 550 450 2 2012 crossing 500 400 3 2012
crossing 450 350 4 2012 indroper 2000 1500 1 2013 indroper 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

please help me to find the query in LINQ-lambda notation
1

1 Answers

2
votes

You can use GroupBy to do this:

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
                                    });