2

I'm trying to write a query that returns all departments whose average salary of employees is within the specified range.

I have something like this:

Query query = pm.newQuery(Employee.class);
query.setResult("department, avg(salary)");
query.setGrouping("department HAVING avg(salary) >= :x && avg(salary) <= :y");
query.setOrdering("2 desc");

Problem is, that avg(salary) is counted again in HAVING, so I get all departments if avg(salary) is in the range or I get empty list of results otherwise. Any ideas?

maszter
  • 3,680
  • 6
  • 37
  • 53
  • There is bug in datanucleus, however there is easy workaround. Instead of avg we can use sum/count and it works fine. – maszter Mar 20 '13 at 19:59

1 Answers1

1

Actually it's fixed since version 3.2.0-m4 Look here: http://www.datanucleus.org/servlet/jira/browse/NUCRDBMS-623

maszter
  • 3,680
  • 6
  • 37
  • 53