OJB ReportQuery 加入问题

发布于 2024-11-05 00:42:30 字数 956 浏览 5 评论 0 原文

给定三个表:

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 列进行分组。

有什么见解吗?

Given three tables:

People: {Person_Id, Age}

Accounts: {Account_Id, Person_Id, Account_Type}

Age_Ranges: {Age_Range_Id, Age_Range_Label, Lower_Bound, Upper_Bound}

I'm trying to represent the following SQL query using OJB (without resorting to a 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'

The java code I have so far looks like this:

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");   
... 

But I'm unsure how to join up with the Age_Ranges table such that I can group on the Age_Range_Label column.

Any insight?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文