从this question派生而来,是否可以对以下SQL语句使用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虽然google提供了一些支持CASE语句的状态HQL,但Hibernate 3.6.6失败了
QuerySyntaxException:意外令牌:大小写
当我在EntityManager实例上创建上面的查询时。
为每个e.type创建另一个查询以手动确定男性的数量,例如,对于每个e.type,这有多糟糕?
SELECT
count(e),
from Department d
JOIN d.employees e
WHERE e.dead = 'maybe', e.type = ugly由于可能有相当多的类型,这可能是缓慢的。我希望数据库能帮我做这项工作。
发布于 2011-08-19 12:12:03
看来,案例陈述是支持的:
http://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html
它们在count()中似乎不起作用。另一种选择是使用sum(当.然后是1其他0端) instead
https://stackoverflow.com/questions/7068051
复制相似问题