Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
2.67/5 (2 votes)
See more:
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
Posted
Updated 11-Jul-13 20:05pm
v2

1 solution

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?
C#
// Make the group first.
var groups = from row in rows
             group row by row.Column1 into g
             select new { GroupKey = g.Key, Value = g };


C#
// 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;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900