SQL语句,子查询数?

我有以下SQL

|name|employees|

雇员

|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 |

我有

SELECT e.type, count(e), count(d) 

FROM Department d

JOIN d.employees e

WHERE e.dead = maybe

GROUP BY e.type

当然,这缺少“男性雇员的数量”。由于不确定,我被困在这里,在哪里指定附加子句e.gender = male。

我忘了提:HQL或标准会很好。

回答:

假设原始查询和架构正确:

SELECT 

e.type,

count(e),

count(d),

count (case when gender = 'male' then 1 else NULL end) AS NumberOfMaleEmployees

from Department d

JOIN d.employees e

WHERE e.dead = 'maybe'

GROUP BY e.type

以上是 SQL语句,子查询数? 的全部内容, 来源链接: utcz.com/qa/405512.html

回到顶部