Maciej Los
Проверить это:
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(){
New DataColumn("Ct", Type.GetType("System.String")),
New DataColumn("Ad", Type.GetType("System.Int32")),
New DataColumn("Qua", Type.GetType("System.Int32")),
New DataColumn("Price", Type.GetType("System.Int32"))})
dt.Rows.Add(New Object(){"A", 1, 34, 700})
dt.Rows.Add(New Object(){"A", 2, 53, 600})
dt.Rows.Add(New Object(){"A", 3, 654, 500})
dt.Rows.Add(New Object(){"B", 3, 45, 1200})
dt.Rows.Add(New Object(){"B", 53, 434, 500})
dt.Rows.Add(New Object(){"B", 5, 63, 200})
dt.Rows.Add(New Object(){"B", 3, 35, 200})
dt.Rows.Add(New Object(){"B", 5, 63, 100})
dt.Rows.Add(New Object(){"C", 31, 45, 2200})
dt.Rows.Add(New Object(){"C", 53, 434, 500})
dt.Rows.Add(New Object(){"C", 51, 63, 200})
dt.Rows.Add(New Object(){"C", 32, 235, 200})
dt.Rows.Add(New Object(){"C", 52, 63, 100})
Dim result = dt.AsEnumerable() _
.GroupBy(Function(x) x.Field(Of String)("Ct")) _
.Select(Function(grp) New With _
{ _
.Ct = grp.Key, _
.Ad = grp.OrderByDescending(Function(x) x.Field(Of Integer)("Price")) _
.Select(Function(x) x.Field(Of Integer)("Ad")).FirstOrDefault(), _
.Qua = grp.OrderByDescending(Function(x) x.Field(Of Integer)("Price")) _
.Select(Function(y) y.Field(Of Integer)("Qua")).FirstOrDefault(), _
.Price = grp.Max(Function(z) z.Field(Of Integer)("Price")) _
}) _
.ToList()
Console.WriteLine(String.Format("{0} {1} {2} {3}", "Ct", "Ad", "Qua", "Price"))
For Each item In result
Console.WriteLine(String.Format("{0} {1} {2} {3}", item.Ct, item.Ad, item.Qua, item.Price))
Next