Help: 如何用 sum 和 count? (sql)# Database - 数据库
f*e
1 楼
我define 了table department,里面有nested table cars,现在怎么count 一共
有多少cars for all departments.
create or replace type CARTYPE as object
(
VIN NUMBER(17),
YEAR NUMBER(4),
MODEL VARCHAR2(60)
);
/
create or replace type CARTABLETYPE as table of CARTYPE;
/
create table Dept(
deptID integer constraint dept_pk primary key,
dname char(20) not null,
cars CartableType
)
nested table cars store as Cartable;
然后我用:
select sum(count(c.*)) from dept D,table(d.cars) c;
有多少cars for all departments.
create or replace type CARTYPE as object
(
VIN NUMBER(17),
YEAR NUMBER(4),
MODEL VARCHAR2(60)
);
/
create or replace type CARTABLETYPE as table of CARTYPE;
/
create table Dept(
deptID integer constraint dept_pk primary key,
dname char(20) not null,
cars CartableType
)
nested table cars store as Cartable;
然后我用:
select sum(count(c.*)) from dept D,table(d.cars) c;