static
void
Main()
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"c1"
,
typeof
(
int
));
dt.Columns.Add(
"c2"
,
typeof
(
string
));
dt.Columns.Add(
"c3"
,
typeof
(
int
));
dt.Rows.Add(1,
"技术部"
, 130);
dt.Rows.Add(2,
"产品部"
, 200);
dt.Rows.Add(3,
"市场部"
, 130);
dt.Rows.Add(3,
"市场部"
, 30);
var query = from d
in
dt.AsEnumerable()
group d by d.Field<
string
>(
"c2"
) into g
select
new
{
c2 = g.Key,
c3 = g.Sum(t => t.Field<
int
>(
"c3"
))
};
query.ToList().ForEach(q => Console.WriteLine(
"{0},{1}"
, q.c2, q.c3));
}