如何在HQL中执行Union SQL语句?
我正在尝试使用HQL(hibernate查询语言)在两个表之间创建一个并集。此SQL脚本可在我的SQL服务器上正常运行:
SELECT COUNT(DISTINCT linkedin_id) as test, school_nameFROM
(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不支持联合。自2005年以来,Hibernate的JIRA中存在一个问题。
以上是 如何在HQL中执行Union SQL语句? 的全部内容, 来源链接: utcz.com/qa/434244.html