您可以按此值降序排列组以获得“MaxRow”,在那里您可以找到
ptime
:
var newSort = dtFinal.AsEnumerable()
.GroupBy(row => new
{
Substation = row.Field<string>("Substation"),
ColumnTitle = row.Field<string>("ColumnTitle")
})
.Select(g => new
{
g.Key.Substation,
g.Key.ColumnTitle,
MaxRow = g.OrderByDescending(row => decimal.Parse(row.Field<string>("ValueAmount"))).First()
})
.Select(x => new
{
ptime = x.MaxRow.Field<string>("ptime"), // voilÃ
x.Substation,
x.ColumnTitle,
ValueAmount = decimal.Parse(x.MaxRow.Field<string>("ValueAmount"))
});
由于使用了查询语法,在本例中,由于
let
:
var newSort = from row in dtFinal.AsEnumerable()
let xRow = new { Row = row, valueAmount = decimal.Parse(row.Field<string>("ValueAmount")) }
group xRow by new
{
Substation = row.Field<string>("Substation"),
ColumnTitle = row.Field<string>("ColumnTitle")
} into grp
let maxRow = grp.OrderByDescending(x => x.valueAmount).First()
select new
{
ptime = maxRow.Row.Field<string>("ptime"),
grp.Key.Substation,
grp.Key.ColumnTitle,
ValueAmount = maxRow.valueAmount
};