6
从this question的衍生产品,它可以使用HQL或条件为下面的SQL语句:尽管谷歌来了CASE语句或者指标
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
有几命中那个状态HQL支持CASE语句,休眠3.6.6失败,并
QuerySyntaxException:意外的标记:CASE
当我创建上面的查询在一个EntityManager实例上。
有多少坏主意,为每个e.type创建另一个查询以手动确定男性的数量,例如,对于每个e.type
SELECT
count(e),
from Department d
JOIN d.employees e
WHERE e.dead = 'maybe', e.type = ugly
由于可能有相当多的类型,这可能很慢。我希望数据库为我完成这项工作。
谢谢,这只是让我从疯了。这是[错误报告](https://hibernate.onjira.com/browse/HHH-4150)。它已经有几年了,但仍然没有解决... –
我们可以使用Criteria查询吗? –
它也适用于Criteria API。 – gillesB