Java HQL或标准中的案例陈述
派生自,是否可以对以下SQL语句使用HQL或条件:Java HQL或标准中的案例陈述,java,sql,hql,criteria-api,Java,Sql,Hql,Criteria Api,派生自,是否可以对以下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推出了一些支
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语句的Hibernate,但Hibernate 3.6.6失败了
QuerySyntaxException:意外标记:大小写
当我在EntityManager实例上创建上面的查询时
为每种e.类型创建另一个查询以手动确定男性的数量,例如为每种e.类型创建另一个查询,这在多大程度上是个坏主意
SELECT
count(e),
from Department d
JOIN d.employees e
WHERE e.dead = 'maybe', e.type = ugly
由于可能有相当多的类型,这可能是缓慢的。我希望数据库能帮我完成这项工作。看来,案例陈述是受支持的:
它们似乎在count()范围内不起作用。另一种方法是使用sum(case when…then 1 else 0 end)谢谢,这让我免于发疯。这是你的电话号码。它已经存在多年了,但仍然没有解决…我们可以使用条件查询吗??