查找以“Action”类型

时间:2016-01-20 08:36:46

标签: sql ms-access join

在我的学位期间,我正在做一门SQL小课程,我对这篇材料非常了解。

鉴于管理有关电影电影数据的网站“eMovies”的数据库。

  

在SQL查询中写入查找正在“Action”类型中播放的演员的名字,而演员Johnny Depp不播放的是那些电影。

enter image description here

表格:

Actors 
    ActorID      PK
    Firstname 
    LastName

Directors 
    DirectorID   PK
    Firstname 
    LastName

Genres 
    GenreID      PK
    GenreDescr 

Movies 
    MovieID      PK
    MovieName 
    Year

ActorsMovies 
    MovieID      PK
    ActorID      PK 

DirectorsMovies 
    MovieID      PK
    DirectorID   PK 

GenresMovies 
    MovieID      PK
    GenreID      PK 

我的尝试:

 SELECT Actors.FirstName,Actors.LastName
 FROM Actors
 INNER JOIN ActorsMovies ON Actors.ActorID= ActorsMovies.ActorID
 INNER JOIN GenresMovies ON ActorsMovies.MovieID=GenresMovies.MovieID
 GROUP BY GenreID
 HAVING GenreID='201' AND NOT IN Actors.ActorID='301855124' ;

2 个答案:

答案 0 :(得分:1)

你试过这个吗?

SELECT Actors.FirstName,Actors.LastName
 FROM Actors
 INNER JOIN ActorsMovies ON Actors.ActorID= ActorsMovies.ActorID
 INNER JOIN GenresMovies ON ActorsMovies.MovieID=GenresMovies.MovieID
 WHERE GenreID='201' AND Actors.ActorID<>'301855124' ;

答案 1 :(得分:0)

SELECT Actors.FirstName,Actors.LastName
FROM Actors
INNER JOIN ActorsMovies t ON Actors.ActorID= t.ActorID
INNER JOIN GenresMovies ON t.MovieID=GenresMovies.MovieID
WHERE GenresMovies.GenreID = 201 and 
not exists (select b.movieid from actorsmovies b where b.ActorID=301855124 and b.movieid = t.movieid) ;

此查询使用NOT EXISTS函数检查每个演员,该演员回答johnny depp未在该电影中播放的请求