0

嗨,我想将我的sql subselect查询转换为hql. 我的 sql 查询如下所示

select distinct sum(goal_score) from(
select user_id,max(goal_score) goal_score from sc_student_final_results ssfr
where month=8 and year=2013 group by goal_id,user_id) ssfr group by ssfr.user_id

对于 abo native sql 命令,我已转换为 hql,如下所示

select distinct sum(goalScore) FROM (select userId,max(goalScore) goalScore FROM 
StudentFinalResults sr where year=:year and month=:month and locationId =:siteid 
group by  userId,goalId) sr group by sr.userId

但我得到了错误

org.hibernate.hql.PARSER - line 1:37: unexpected token: (
org.hibernate.hql.PARSER - line 1:52: unexpected token: max
unexpected token: ( near line 1, column 37 [select distinct sum(goalScore) 
FROM (select userId,max(goalScore) goalScore FROM
net.sankhya.scorecards.model.StudentFinalResults sr where year=:year and 
month=:month and locationId =:siteid group by userId,goalId) sr group by sr.userId]
4

1 回答 1

0

请用这个更新您的查询,它可能会成功!

select distinct sum(sr3.goalScore) FROM (select userId,max(goalScore)  FROM 
StudentFinalResults sr2 where year=:year and month=:month and locationId =:siteid 
group by  userId,goalId) sr3 group by sr3.userId
于 2013-08-22T04:55:25.767 回答