分组,总结并找到前10名 [英] Group by, sum and find top 10

查看:103
本文介绍了分组,总结并找到前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;
}


这篇关于分组,总结并找到前10名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆