如何在HQL中执行联合SQL语句?

编程入门 行业动态 更新时间:2024-10-25 23:34:03
本文介绍了如何在HQL中执行联合SQL语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图使用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:意外的标记:(在第1行第83列[select count(distinct linkedinId)as countOfEdu,schoolName as SchoolName from(SELECT * FROM alumEducation UNION SELECT * FROM alumConnectionEducations)AS UNIONS where schoo lName ='Duquesne University']

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

感谢 jason

解决方案

HQL不支持联合。 Hibernate的JIRA中存在一个问题,该问题自2005年开放。

I'm trying to create a Union between two tables, using HQL (Hibernate Query Language). This SQL script works fine on my SQL server:

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'

the problem is, when i try to run it in grails like this:

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'" )

i get this error:

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']

How can I run the above SQL statement in grails?

thanks jason

解决方案

Unions are not supported by HQL. There is an issue in Hibernate's JIRA that is open since 2005.

更多推荐

如何在HQL中执行联合SQL语句?

本文发布于:2023-10-23 00:00:55,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   如何在   HQL   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!