2

给定三个表:

People: {Person_Id, Age}

Accounts: {Account_Id, Person_Id, Account_Type}

Age_Ranges: {Age_Range_Id, Age_Range_Label, Lower_Bound, Upper_Bound}

我正在尝试使用 OJB 表示以下 SQL 查询(不使用 QueryBySQL):

select ar.Age_Range_Label, count(a.Account_Id)
from People p
inner join Accounts a on p.Person_Id = a.Person_Id
inner join Age_Ranges ar on p.Age between ar.Lower_bound and ar.Upper_Bound
where a.Account_Type = 'Chequing'

到目前为止,我的 java 代码如下所示:

Criteria criteria = new Criteria();
criteria.addEqualTo("Account_Type", "Chequing");

// join on Age_Ranges based on the person's Age
criteria.???

ReportQueryByCriteria q = QueryFactory.newReportQuery(Accounts.class, criteria);
q.setAttributes(new String[] {"Age_Range_Label", "count(Account_Id)"});
q.addGroupBy("Age_Range_Label");   
... 

但我不确定如何加入 Age_Ranges 表,以便我可以在 Age_Range_Label 列上进行分组。

有什么见解吗?

4

0 回答 0