-2

我试图从我的结果中排除一些东西。

我要加入 3 个表,1 个带电影,1 个带流派,1 个将这 2 个表结合起来。

因此,结果为每种类型的每部电影提供了一行。

因此,如果我有 2 部电影,每 3 种类型,我会得到 6 个结果。

现在我想说我不想要这种特定类型的电影。如果我这样说AND tblmoviegenre.ID <> genre.ID我只少了 1 行,但电影仍在结果中,只是没有特定类型的那一行。

有谁知道如何解决这一问题?

4

3 回答 3

3

我不确定你想要什么。如果我明白了,这应该可以正常工作

select distinct M.IdMovie, M.MovieName --And Other Fields
from Movies M
inner join MoviesPerGenre MPG on M.IdMovie = MPG.IdMovie
inner join Genre G on MPG.IdGenre = G.IdGenre
where M.IdMovie not in (Select IdMovie from MoviesPerGenre  where IdGenre = 58)

将 58 替换为您要过滤的类型的 Id

于 2012-08-28T19:31:12.920 回答
0

你想排除一部电影,如果它有那种类型,即使它也属于其他不被排除的类型?

select <whatever>
from movie, genre, moviegenre
where <join conditions>
and not exists (select 'x' from moviegenre where movie.id = moviegenre.id and moviegenre = "some genere you want to exclude)
于 2012-08-28T19:30:18.223 回答
0

假设您的第三张桌子是

    | movie | genre
---------- -------------
       1    |   2
       2    |   2
       3    |   3
       3    |   2
       4    |   1

现在你想排除所有类型 2 然后你可以写

SELECT movie.name,genre.name 
FROM   movie inner join combine_info on movie.id = combine_info.movie, 
       genre inner join combine_info on genre.id = combine_info.movie
WHERE  movie.id NOT IN(SELECT movie 
                           FROM   combine_info 
                           WHERE  genre = 2); 
于 2012-08-28T19:33:04.523 回答