gpt4 book ai didi

hibernate - HQL在具有and max的情况下产生意外的AST节点

转载 作者:行者123 更新时间:2023-12-02 15:29:50 25 4
gpt4 key购买 nike

我想做一个非常简单的查询。

在SQL中是:

select * from table group by portfolio_id HAVING max(date)

在grails中,我做了这样的事情:
def result = Table.executeQuery("from Table group by portfolio having max(date)")

但是我得到了一个 意外的AST节点

我不知道,我读了一些文档,但仍然无法理解,为什么它不起作用。

这里的错误信息更详细
| Error 2014-01-29 17:20:15,400 [http-bio-8080-exec-8] ERROR hql.PARSER - <AST>:1:97: unexpected AST node: max 

| Error 2014-01-29 17:20:15,426 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver - QuerySyntaxException occurred when processing request: [GET] /Lumen/Controller unexpected AST node: max near line 1, column 97 [select portfolio.id,date from com.gwm.lumen.Table group by portfolio.id having max(date)].

Stacktrace如下:
Message: unexpected AST node: max near line 1, column 97 [select portfolio.id,date from com.gwm.lumen.Table group by portfolio.id having max(date)]

最佳答案

如果基础数据库是MySQL,则不能在max()子句中使用聚合函数[在这种情况下为having]。

SQL functions and aggregate functions are allowed in the having and order by clauses if they are supported by the underlying database (i.e., not in MySQL).



@摘录自 Hibernate Docs on group by clause

我不确定最新的MySQL方言是否支持它。

关于hibernate - HQL在具有and max的情况下产生意外的AST节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21434946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com