您好我想将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
对于我已经转换为hql的abo native sql命令,如下所示
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]
答案 0 :(得分: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