1

我是 HQL 的新手,我正在尝试这样做:

select count(T) from (
    select inscription, max(wrd_step) as max 
    from table aa 
    where rd_context = ? 
    group by inscription
) as T
where T.max = ?

错误是:

Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 21 [select count(T) from( select inscription, max(wrd_step) from table aa where rd_context = ? group by inscription) as T where T.max = ?]

谢谢

编辑 :

HQL 中的查询是:

SELECT count(distinct inscription)
FROM Entity
WHERE inscription in (
    select distinct inscription
    from Entity 
    where rd_context = ?
    group by inscription
    having max(wrd_step) = ?
)
4

1 回答 1

1

Hibernate 文档指出:

请注意,HQL 子查询只能出现在 select 或 where 子句中。

http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#queryhql-subqueries

但假设table是一个映射实体(是吗?),你可以这样做(未经测试):

select count(aa)
from table aa 
where rd_context = :param1 
group by inscription
having max(wrd_step) = :param2
于 2013-06-11T21:27:25.383 回答