-1

我将如何查询这 4 个表以查看Apocalypse Now中的演员?

Studio Table
studioID  studioName
--------  --------
1         Lucasfilm
2         Amblin Entertainment
3         Zoetrope Studios

Movie Table
movieID   movieName        studioID    castID
--------  --------        --------    --------
1         Star Wars            1          1
2         Indiana Jones        1          2
3         Back to the Future   2          3
4         Apocalypse Now       3          4

Cast Table
castID   movieID  actorID  roleName
-------- -------- -------- --------
1          1         1     Han Solo
2          2         1     Indiana Jones
3          3         3     Doc Brown
4          4         1     Colonel Lucas
5          4         2     Tyrone Miller

Actor Table
actorID  lastName     firstName
-------- --------     --------
1        Ford         Harrison
2        Fishburne    Laurence
3        Lloyd        Christopher

现在我在想:

SELECT Studio.studioName, Movie.movieName, Cast.roleName, Actor.firstName, Actor.lastname
FROM Studio, Movie, Actor, Cast 

WHERE Cast.castID = Movie.castID and Movie.movieName = 'Apocalypse Now'

ORDER BY Actor.lastname

不太确定如何加入表格。

=.=.=.=.=.=.=.=.=

4

1 回答 1

2

尝试这个..

SELECT a.*
FROM Movie m
LEFT JOIN Cast c on (c.movieID = m.movieID)
LEFT JOIN Actor a on (a.actorID = c.actorID)
WHERE m.movieName='Apocalypse Now';

如果您还需要一个工作室加入工作室表:

SELECT a.actorID, a.firstName, a.lastName, s.studioName
FROM Movie m
LEFT JOIN Cast c on (c.movieID = m.movieID)
LEFT JOIN Actor a on (a.actorID = c.actorID)
LEFT JOIN Studio s on (m.studioID = s.studioID)
WHERE m.movieName='Apocalypse Now';
于 2013-10-14T23:31:27.243 回答