我有表“客户”和列“ID”、“国家”、“性别”。我想要的是在同一个查询中获得按国家字段分组的客户总数和男性和女性总数。我已经在sql查询中完成了。有用。但找不到如何在 LINQ 中实现它。
SELECT c.country, COUNT(c.id) AS TotalClients,
ISNULL(max(c2.total),0) AS TotalMales,
COUNT(c.id)-ISNULL(MAX(c2.total),0) AS TotalFemails,
FROM Clients c
LEFT OUTER JOIN(
SELECT country, count(id) AS total FROM Clients
WHERE sex='male'
GROUP BY country
) c2
ON c2.country = c.country
GROUP BY c.country
ORDER BY c.country
有什么建议么?