views:

117

answers:

1

How can I write the below HQL query using the Criteria API?

select s.Name, sum(q.PointsObtained), sum(q.TotalPoints)
from Student s join s.Quizzes q
group by s.Name
order by (sum(q.PointsObtained) / sum(q.TotalPoints)) desc
A: 

It's not supported by HQL or the Critieria API. See 14.12. The group by clause: "Neither the group by clause nor the order by clause can contain arithmetic expressions." I assume you mean SQL query, not HQL query, in your question.

Jamie Ide
Thanks for the reply. The query I posted is HQL and it gives me the correct results. Also, please check section 14.14 in the document you linked where there are examples of computed columns used in the ORDER BY clause. So, is this possible using Criteria API?