【发布时间】:2017-03-26 15:08:17
【问题描述】:
我的表 CUSTOMER_TABLE 有一个对 ACCOUNT_TABLE 的引用的嵌套表。 ACCOUNT_TABLE 中的每个帐户都有一个对分支的引用:branch_ref。
CREATE TYPE account AS object(
accid integer,
acctype varchar2(15),
balance number,
rate number,
overdraft_limit integer,
branch_ref ref branch,
opendate date
) final;
CREATE TYPE customer as object(
custid integer,
infos ref type_person,
accounts accounts_list
);
create type branch under elementary_infos(
bid integer
) final;
所有表都继承自这些对象类型。
我想选择每个分行余额最高的账户。我是用这个查询来做的:
select MAX(value(a).balance), value(a).branch_ref.bid
from customer_table c, table(c.accounts) a
group by value(a).branch_ref.bid
order by value(a).branch_ref.bid;
返回:
MAX(VALUE(A).BALANCE) VALUE(A).BRANCH_REF.BID
--------------------------------------- ---------------------------------------
176318.88 0
192678.14 1
190488.19 2
196433.93 3
182909.84 4
但是,如何从显示的最大帐户中选择其他属性?我想显示所有者的姓名和客户的 ID。 id 直接是客户的一个属性。但是名称存储在对 person_table 的引用中。所以我也必须选择 c.id & deref(c.infos).names.surname。
如何使用我的 MAX() 查询选择这些其他属性?
谢谢
【问题讨论】:
-
Guilhem 能否请您包含这些表
CUSTOMER_TABLE和“ACCOUNT_TABLE”的 DDL?谢谢