gpt4 book ai didi

hibernate - 如何在HQL中进行Union SQL语句?

转载 作者:行者123 更新时间:2023-12-02 19:43:39 28 4
gpt4 key购买 nike

我正在尝试使用 HQL(Hibernate 查询语言)在两个表之间创建联合。这个 SQL 脚本在我的 SQL 服务器上运行良好:

SELECT COUNT(DISTINCT linkedin_id) as test, school_name
FROM
(SELECT * FROM alum_education
UNION
SELECT * FROM alum_connection_educations) AS UNIONS where school_name='some string'

问题是,当我尝试像这样在 grails 中运行它时:

     def countOfEdu = AlumEducation.executeQuery("select count (distinct linkedinId ) as countOfEdu, schoolName as SchoolName from (SELECT * FROM alumEducation UNION SELECT * FROM alumConnectionEducations) AS UNIONS where schoolName='some string'" )

我收到此错误:

  org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 83 [select count(distinct linkedinId )  as countOfEdu, schoolName as SchoolName  from (SELECT * FROM alumEducation UNION SELECT * FROM alumConnectionEducations) AS UNIONS where schoolName='Duquesne University']

如何在 grails 中运行上面的 SQL 语句?

谢谢杰森

最佳答案

HQL 不支持联合。有一个issue在自 2005 年开放的 Hibernate JIRA 中。

关于hibernate - 如何在HQL中进行Union SQL语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7182433/

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