JDOQL 子查询 - Class 名称 _ 无法解析
JDOQL subqueries - Class name _ could not be resolved
我是 JDOQL 新手,遇到以下问题。我正在尝试获取部门的平均工资,然后 select 平均工资高于某个值的部门。
Query averageSalaryByDep = pm.newQuery(Employee.class);
averageSalaryByDep.setResult("department, avg(salary)");
averageSalaryByDep.setGrouping("department");
Query qry = pm.newQuery(Department.class);
qry.setFilter("this.name == dep.name && averageSalary > 10000");
qry.declareVariables("Department dep, double averageSalary");
qry.addSubquery(averageSalaryByDep, "Department dep, double averageSalary", null);
我目前收到的错误信息:
javax.jdo.JDOUserException: Class name averageSalary could not be resolved
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:636)
at org.datanucleus.api.jdo.JDOQuery.executeInternal(JDOQuery.java:391)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:216)
一个子查询有一个单一的变量名(returns 一个单一的东西)。如果不确定某事,请输入单字符串查询的样子(以及结果 SQL),然后它应该很清楚。 JDO 规范有一些有用的例子 IIRC
关于你想要检索的内容,我建议你看看更像
的东西
Query averageSalarySubq = pm.newQuery(Employee.class);
averageSalarySubq.setResult("avg(salary)");
averageSalarySubq.setFilter("this.department = :outerDepartment");
Query qry = pm.newQuery(Department.class);
qry.setFilter("averageSalary > 10000");
qry.declareVariables("double averageSalary");
qry.addSubquery(averageSalarySubq, "double averageSalary", null, "this");
相当于
SELECT FROM mydomain.Department WHERE
(SELECT AVG(e.salary) FROM mydomain.Employee e WHERE e.department = this) > 10000
因此子查询得到的是平均工资,但加入了外部查询部门。定义 SQL 会告诉你这是否是你想要的,但无论哪种方式,子查询都是针对单个变量的
我是 JDOQL 新手,遇到以下问题。我正在尝试获取部门的平均工资,然后 select 平均工资高于某个值的部门。
Query averageSalaryByDep = pm.newQuery(Employee.class);
averageSalaryByDep.setResult("department, avg(salary)");
averageSalaryByDep.setGrouping("department");
Query qry = pm.newQuery(Department.class);
qry.setFilter("this.name == dep.name && averageSalary > 10000");
qry.declareVariables("Department dep, double averageSalary");
qry.addSubquery(averageSalaryByDep, "Department dep, double averageSalary", null);
我目前收到的错误信息:
javax.jdo.JDOUserException: Class name averageSalary could not be resolved
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:636)
at org.datanucleus.api.jdo.JDOQuery.executeInternal(JDOQuery.java:391)
at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:216)
一个子查询有一个单一的变量名(returns 一个单一的东西)。如果不确定某事,请输入单字符串查询的样子(以及结果 SQL),然后它应该很清楚。 JDO 规范有一些有用的例子 IIRC
关于你想要检索的内容,我建议你看看更像
的东西Query averageSalarySubq = pm.newQuery(Employee.class);
averageSalarySubq.setResult("avg(salary)");
averageSalarySubq.setFilter("this.department = :outerDepartment");
Query qry = pm.newQuery(Department.class);
qry.setFilter("averageSalary > 10000");
qry.declareVariables("double averageSalary");
qry.addSubquery(averageSalarySubq, "double averageSalary", null, "this");
相当于
SELECT FROM mydomain.Department WHERE
(SELECT AVG(e.salary) FROM mydomain.Employee e WHERE e.department = this) > 10000
因此子查询得到的是平均工资,但加入了外部查询部门。定义 SQL 会告诉你这是否是你想要的,但无论哪种方式,子查询都是针对单个变量的