【发布时间】:2013-05-19 14:15:24
【问题描述】:
我对使用 Linq 到实体的计数命令有疑问。 我想做的是用我的员工的公民身份来统计所有的性别。
公民身份 0 - all ; 1 = single ; 2 - married
我是 linq to entity 的新手 这是我的 SQL 命令代码。
我不知道如何转换这个。
select '0' as UserID, COUNT(a.Gender) as TotalCount from Employees a
union all
select '1' as UserID, COUNT(a.Gender) as TotalCount from Employees a where a.CivilStatus = 1
union all
select '2' as UserID, COUNT(a.Gender) as TotalCount from Employees a where a.CivilStatus = 2
像这样
UserID | TotalCount
0 | 10
1 | 7
2 | 3
提示
假设我有 10 名员工(男性和女性),我想知道其中有多少是单身或已婚。
谢谢。 =)
【问题讨论】:
-
仅供参考,看看linqpad.net它可能会帮助你
-
我可以帮助你,但我不明白这个问题......你想计算所有可能的性别吗?我可以很简短地回答这个问题:2...请更准确!
-
它应该计算所有civilstatus的totalcount,值为1;和值为 2
-
@jaydotnet 我更新了问题
标签: sql select count linq-to-entities