我想在兩個表之間創建一個使用HQL(Hibernate查詢語言)的聯合。該SQL腳本工作正常,我的SQL服務器上:如何在HQL中執行聯合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語句?
感謝 傑森
可能重複:http://stackoverflow.com/questions/201023/hibernate-union-alternatives –
刪除評論 – jellobird