使用linq计算重复记录 .................................................. .................................................. ..............................................
Col1 col2
x a
x a
x b
x b
y c
y c
y d
y d
z e
z e
z f
现在我想要数如下
x a 2
x b 2
y c 2
y d 2
in linq plese任何人协助我
答案 0 :(得分:2)
table
.GroupBy(x=>new{x.col1,x.clo2})
.Select(x=>new{ x.key.col1,x.key.col2,x.Count(z=>z.col1)
答案 1 :(得分:0)
var Result =
from t in table
group t by new
{
t.col1,
t.col2,
} into gt
select new
{
col1 = gt.Key.col1,
col2 = gt.Key.col2,
count = gt.Count(),
};