I'm implementing movies database, I have this task in my university.
I have tables: movies
, people
, movie_people
, awards
. Both people
and movies
have field with id of award, which can be NULL
.
I can't get how to make SQL query which will show list of people, who played only in films which have awards. Can you help me with that?
CREATE TABLE "LAB"."MOVIE"
( "MOVIE_ID" NUMBER NOT NULL ENABLE,
"TITLE" VARCHAR2(219 BYTE) NOT NULL ENABLE,
"YEARMADE" DATE,
"COUNTRY" VARCHAR2(40 BYTE),
"RUNNINGTIME" NUMBER,
"LANGUAGE" VARCHAR2(40 BYTE),
"TAG_ID" NUMBER NOT NULL ENABLE,
"REVIEW_ID" NUMBER,
"AWARD_ID" NUMBER,
PRIMARY KEY ("MOVIE_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ENABLE,
FOREIGN KEY ("TAG_ID")
REFERENCES "LAB"."TAG" ("TAG_ID") ON DELETE CASCADE ENABLE,
FOREIGN KEY ("REVIEW_ID")
REFERENCES "LAB"."REVIEW" ("REVIEW_ID") ON DELETE CASCADE ENABLE,
CONSTRAINT "AWARD_ID" FOREIGN KEY ("AWARD_ID")
REFERENCES "LAB"."AWARD" ("AWARD_ID") ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ;
CREATE TABLE "LAB"."MOVIE_PEOPLE"
( "MOVIE_ID" NUMBER NOT NULL ENABLE,
"PEOPLE_ID" NUMBER NOT NULL ENABLE,
"ROLE" VARCHAR2(60 BYTE) NOT NULL ENABLE,
FOREIGN KEY ("MOVIE_ID")
REFERENCES "LAB"."MOVIE" ("MOVIE_ID") ON DELETE CASCADE ENABLE,
FOREIGN KEY ("PEOPLE_ID")
REFERENCES "LAB"."PEOPLE" ("PEOPLE_ID") ON DELETE CASCADE ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ;
CREATE TABLE "LAB"."PEOPLE"
( "PEOPLE_ID" NUMBER NOT NULL ENABLE,
"FAMILYNAME" VARCHAR2(40 BYTE) NOT NULL ENABLE,
"GIVENNAME" VARCHAR2(40 BYTE) NOT NULL ENABLE,
"GENDER" CHAR(1 BYTE) NOT NULL ENABLE,
"DATEOFBIRTH" DATE,
"TAG_ID" NUMBER,
"AWARD_ID" NUMBER,
PRIMARY KEY ("PEOPLE_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ENABLE,
FOREIGN KEY ("TAG_ID")
REFERENCES "LAB"."TAG" ("TAG_ID") ON DELETE CASCADE ENABLE,
FOREIGN KEY ("AWARD_ID")
REFERENCES "LAB"."AWARD" ("AWARD_ID") ON DELETE CASCADE ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ;
CREATE TABLE "LAB"."AWARD"
( "AWARD_ID" NUMBER NOT NULL ENABLE,
"TITLE" VARCHAR2(40 BYTE) NOT NULL ENABLE,
"YEAR" DATE NOT NULL ENABLE,
PRIMARY KEY ("AWARD_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…