Saturday, 17 August 2013

How to do a division, calculate a percentage in HQL?

How to do a division, calculate a percentage in HQL?

I'm trying to calculate a percentage but the compiler keeps telling me it
doesn't expect the slash and the third select statement.
Query query = session.createQuery("SELECT
(SELECT COUNT(*) FROM Reservation r WHERE r.begin BETWEEN :start AND :end)
/
(SELECT COUNT(*) FROM Reservation res WHERE res.begin BETWEEN :start AND
:end AND res.contract IS NOT NULL) * 100");
When I try to run this, it gives me this error:
Exception in thread "main"
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected end of
subtree
What am I doing wrong? Thanks in advance!

No comments:

Post a Comment