sqlplus使用子查询

时间:2013-11-01 15:20:39

标签: sql database

我有3张桌子,必须找出每个申请人申请的申请人编号,姓名和职位总数。

CREATE TABLE    APP (
appNum      varchar2(10)    not null,
appName     varchar2(70),
constraint applicant_Pkey primary key (appNum)
);

CREATE TABLE    POS (
posNum          varchar2(10)    not null,
posStartOfferDt     date        not null,
constraint pos_Pkey primary key (posNum, posStartOfferDt)
);



CREATE TABLE    APPLICATION (
appcnPosNum     varchar2(10)    not null,
appcnPosStOffrDt    date        not null,
appcnAppNum     varchar2(10)    not null,
appcnDt         date,
constraint application_Pkey primary key (appcnPosNum, appcnPosStOffrDt, appcnAppNum),
constraint application_Fkey1 foreign key (appcnPosNum, appcnPosStOffrDt) references     POSITION(posNum, posStartOfferDt),
constraint application_Fkey2 foreign key (appcnAppNum) references APPLICANT(appNum)
);

我尝试过使用子查询,自然加入,但一切都不适合我。

1 个答案:

答案 0 :(得分:1)

SELECT   appNum, appName, COUNT(*)
FROM     applicant
JOIN     application ON applicant.appNum = application.appcnAppNum
GROUP BY appNum, appName