Industry と Weight でグループ化されたグループから 1 つの項目だけを検索するクエリを作成しようとしています。次に、この項目から、Weight が Max で Balance も Max である場所を取得する必要があります。これは例です。
var data = new[] {
new {ID = 1, Industry = 2, Weight = 2, Balance = 500},
new {ID = 2, Industry = 2, Weight = 2, Balance = 300},
new {ID = 3, Industry = 2, Weight = 1, Balance = 100},
new {ID = 5, Industry = 4, Weight = 1, Balance = 100},
new {ID = 6, Industry = 4, Weight = 2, Balance = 150},
new {ID = 7, Industry = 4, Weight = 1, Balance = 300},
};
var res = from a in data group a by new {a.Industry, a.Weight} into g
let ID = g.First().ID
let Balance = g.Max(a => a.Balance)
select new { ID, g.Key.Industry, g.Key.Weight, Balance};
Console.WriteLine(res);
結果として、2つのレコードのみを取得する必要があります
ID Industry Weight Balance
1 2 2 500
6 4 2 150
しかし、上記のクエリでは 4 つのレコードが得られました 何かアドバイスはありますか?
よろしく、 ドミトリー