首页
学习
活动
专区
圈层
工具
发布

HQL变换
EN

Stack Overflow用户
提问于 2013-06-11 22:54:18
回答 1查看 405关注 0票数 1

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

代码语言:javascript
复制
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 = ?

错误是:

代码语言:javascript
复制
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中的查询为:

代码语言:javascript
复制
SELECT count(distinct inscription)
FROM Entity
WHERE inscription in (
    select distinct inscription
    from Entity 
    where rd_context = ?
    group by inscription
    having max(wrd_step) = ?
)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-12 05:27:25

Hibernate文档声明:

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

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

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

代码语言:javascript
复制
select count(aa)
from table aa 
where rd_context = :param1 
group by inscription
having max(wrd_step) = :param2
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17047213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档