jpql subtract the results of two count functions
I have an entity which consists of two many-to-many relations: MainEntity
has many of As and MainEntity has many of Bs, where A and B is of the same
type. Example for the following JQL: If "ob" has got 4 "As" and 5 "Bs" i
need the result of -1 in the placeholder "difference" but it allways
returns 0.
String query = "SELECT ob, (COUNT(A) - COUNT(B)) difference" +
+ " FROM MainEntity ob "
+ " JOIN ob.listA A "
+ " JOIN ob.listB B "
+ " GROUP BY ob "
+ " WHERE ob=:PARAM ";
The Following Example is working:
"SELECT COUNT(A) FROM MainEntity ob JOIN ob.listA A "
+ "WHERE ob=:PARAM"
It returns 5 if ob has 5 items in its list "listA". Can anybody help me to
construct the right JPQL?
No comments:
Post a Comment