我正在尝试查询某些内容,例如根据导演名称“Ang Lee”检索电影名称。我把电影和导演分成了两张桌子。我有第三张表,其中包含电影ID和导演ID,我试图将所有内容与之结合在一起。所以我需要做的一件事就是找到以'Ang Lee'为名的电影(MId,Title,ReleaseDate)。我必须发送什么类型的查询才能获得此结果?以下是我的代码背景:
CREATE TABLE MOVIE(
MId INTEGER,
Title VARCHAR(50),
ReleaseDate DATE,
Budget DOUBLE,
PRIMARY KEY (MId)
);
CREATE TABLE DIRECTOR(
DId INTEGER,
Name VARCHAR(30),
DateOfBirth DATE,
PRIMARY KEY (DId)
);
CREATE TABLE DIRECTED(
DirectorId INTEGER,
MovieId INTEGER,
PRIMARY KEY(DirectorId, MovieId),
FOREIGN KEY(DirectorId) REFERENCES DIRECTOR(DId),
FOREIGN KEY(MovieId) REFERENCES MOVIE(MId)
);
INSERT INTO MOVIE VALUES(1, 'Life of Pi', '2012-11-21', 120000000);
INSERT INTO MOVIE VALUES(3, 'Argo', '2012-10-12', 44500000);
INSERT INTO MOVIE VALUES(7, 'The Dark Knight Rises', '2012-07-20', 250000000);
INSERT INTO MOVIE VALUES(15, 'Thor', '2011-12-10', 150000000);
INSERT INTO MOVIE VALUES(45, 'The Sessions', '2012-01-23', 1000000);
INSERT INTO MOVIE VALUES(65, 'Batman Begins', '2005-06-15', 150000000);
INSERT INTO MOVIE VALUES(86, 'Goodfellas', '1990-09-19', 25000000);
INSERT INTO MOVIE VALUES(95, 'The Departed', '2006-10-06', 90000000);
INSERT INTO MOVIE VALUES(103, 'There's Something about Mary', '1998-07-15', 23000000);
INSERT INTO MOVIE VALUES(123, 'The Matrix', '1999-05-31', 63000000);
INSERT INTO MOVIE VALUES(144, 'Lust, Caution', '2007-09-28', 15000000);
INSERT INTO DIRECTOR VALUES(4, 'Ang Lee', '1954-10-23');
INSERT INTO DIRECTOR VALUES(5, 'Ben Affleck', '1972-08-15');
INSERT INTO DIRECTOR VALUES(8, 'Christopher Nolan', '1970-07-30');
INSERT INTO DIRECTOR VALUES(9, 'Kenneth Branagh', '1960-12-10');
INSERT INTO DIRECTOR VALUES(13, 'Ben Lewin', '1946-01-23');
INSERT INTO DIRECTOR VALUES(23, 'Martin Scorsese', '1942-11-17');
INSERT INTO DIRECTOR VALUES(25, 'Christopher Nolan', '1970-07-30');
INSERT INTO DIRECTOR VALUES(33, 'Peter Farrelly', '1956-12-17');
INSERT INTO DIRECTOR VALUES(34, 'Robert Farrelly', '1958-06-17');
INSERT INTO DIRECTOR VALUES(45, 'Lana Wachowski', '1965,06-21');
INSERT INTO DIRECTOR VALUES(46, 'Andrew Wachowski', '1967-12-29');
INSERT INTO DIRECTED VALUES(4, 1);
INSERT INTO DIRECTED VALUES(5, 3);
INSERT INTO DIRECTED VALUES(8, 7);
INSERT INTO DIRECTED VALUES(9, 15);
INSERT INTO DIRECTED VALUES(13, 45);
INSERT INTO DIRECTED VALUES(25, 65);
INSERT INTO DIRECTED VALUES(23, 86);
INSERT INTO DIRECTED VALUES(23, 95);
INSERT INTO DIRECTED VALUES(33, 103);
INSERT INTO DIRECTED VALUES(34, 103);
INSERT INTO DIRECTED VALUES(45, 123);
INSERT INTO DIRECTED VALUES(46, 123);
INSERT INTO DIRECTED VALUES(4, 144);
答案 0 :(得分:2)
SELECT m.MId, m.Title, m.ReleaseDate
FROM DIRECTED dir, DIRECTOR d, MOVIE m WHERE
d.Name = 'Ang Lee' AND
d.DId = dir.DirectorId AND
dir.MovieId = m.MId