Linq与团队有计数

时间:2010-01-16 19:59:12

标签: linq count group-by having

如何在linq(vb.net)中编写此查询?

 select B.Name
 from Company B
 group by B.Name
 having COUNT(1) > 1

3 个答案:

答案 0 :(得分:250)

像这样:

from c in db.Company
group c by c.Name into grp
where grp.Count() > 1
select grp.Key

或者,使用方法语法:

Company
    .GroupBy(c => c.Name)
    .Where(grp => grp.Count() > 1)
    .Select(grp => grp.Key);

答案 1 :(得分:6)

对于任何想要在vb中执行此操作的人(就像我一样,找不到任何东西)

From c In db.Company 
Select c.Name Group By Name Into Group 
Where Group.Count > 1

答案 2 :(得分:-2)

以下解决方案可能会对您有所帮助。

[Running] /home/pabc/.nvm/versions/node/v13.13.0/bin/node "/home/pabc/CODE_PROJECTS/Odin_Project/randomCode/test.js"

[Done] exited with code=0 in 0.025 seconds