SQL语句、子查询计数?
我有以下 SQL 表
Department
|name|employees|
Employee
|name|gender|type|dead |
|John|male |good|yes |
|Mary|female|bad |no |
|Joe |male |ugly|maybe|
我想编写一个返回
| type | n of employees | n of male employees | n of departments |
I've got
SELECT e.type, count(e), count(d)
FROM Department d
JOIN d.employees e
WHERE e.dead = maybe
GROUP BY e.type
That 的语句,当然,缺少“n ofmaleEmployees”。我被困在这里,因为我不确定在哪里指定附加子句 e.gender =male。
我忘了提:HQL 或标准会很好。
I've got the following SQL tables
Department
|name|employees|
Employee
|name|gender|type|dead |
|John|male |good|yes |
|Mary|female|bad |no |
|Joe |male |ugly|maybe|
I would like to write a statement that returns
| type | n of employees | n of male employees | n of departments |
I've got
SELECT e.type, count(e), count(d)
FROM Department d
JOIN d.employees e
WHERE e.dead = maybe
GROUP BY e.type
That's missing the 'n of male employees', of course. I'm stuck here, since I'm not sure, where to specify the additional clause e.gender = male.
I forgot to mention: HQL or criteria would be nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您的原始查询和架构是正确的:
Assuming your original query and schema is correct:
仅供参考:
适用于 HQL。谢谢大家!
Just for reference:
works in HQL. Thanks everyone!