SELECT
( SELECT d.DeptName FROM Dept d WHERE d.Id=p.DeptId ) DeptName,
count( p.DeptId) AS Count
FROM
Person p
GROUP BY
p.DeptId
var dept = (from p in db.Person
group p by p.DeptId into g
join d in db.Dept
on g.Key equals d.Id
select new
{
count=g.Count(),
g.Key,
DeptName = d.DeptName
}
).ToList();
搜索微软知识时加 msdn en-us=>zh-cn