分组,总结并找到前10名
问题描述:
从数据表中我必须按特定列进行分组,然后求它并使用Linq找到要在图表中绘制的前10行
from a data table i have to group by a particular column, and sum it and find the top 10 rows to plot in chart using Linq
答
签出 101 LINQ示例 [ ^ ]
通过这个你应该能够找到正确的LINQ短语。
但也许这样的事情可以给你一个开始?
Check out 101 LINQ Samples[^] from Microsoft.
Through this you should be able to find the right LINQ phrase.
But perhaps something like this can give you a start?
// Make the group first.
var groups = from row in rows
group row by row.Column1 into g
select new { GroupKey = g.Key, Value = g };
// Get top 10
var results = (from g in groups
order by g.Value.Column2
select g.Value).Take(10);
// look at the results
foreach (var result in results)
{
var name = result.Column2;
}