How to order records by a calculated column in the criteria API?

How can I write the HQL query below 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
+3
source share
1 answer

It is not supported by HQL or the Critieria API. See 14.12. Group by clause : "Neither the group by clause nor the order by clause may contain arithmetic expressions." I assume that you mean an SQL query, not an HQL query, in your question.

0
source

Source: https://habr.com/ru/post/1739451/


All Articles