2013-04-15 82 views
1

最大值和最小值率特定區域-Lambda查詢

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 

請幫我找到LINQ,拉姆達符號查詢

回答

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

thanx蘆葦,但它不起作用 – Pradeep

+0

@Pradeep它做什麼不同於你想要的? –

+0

它每年都會返回記錄。但在你的解決方案的幫助下,我只嘗試了groupBy區域和問題解決。感謝您的幫助。 – Pradeep

相關問題