0

我有以下架构。

MovieInfo (mvID, title, rating, year, length, studio)
DirectorInfo(directorID, firstname, lastname)
DirectInfo(mvID*, directorID*)
GenreInfo(mvID*, genre)

我希望输出仅在一种类型中工作过的演员的详细信息列表,例如动作片。电影与类型是一对多的关系。

到目前为止我有这个,但我遇到了错误。

SELECT ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname
FROM ActorInfo, GenreInfo, CastInfo
WHERE CastInfo.mvID = GenreInfo.mvID
AND CastInfo.ActorID = ActorInfo.ActorID
AND Genreinfo.genre = 'ACtion'
MINUS
(SELECT ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname,
FROM ActorInfo, GenreInfo, CastInfo
WHERE CastInfo.mvID = GenreInfo.mvID
AND CastInfo.ActorID = ActorInfo.ActorID
AND Genreinfo.genre != 'Action')
GROUP BY ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname, 
4

2 回答 2

0

也许像这样:

select
        ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname, max(genre)
from
        ActorInfo,
        GenreInfo,
        CastInfo
where
        CastInfo.ActorID = ActorInfo.ActorID and
        CastInfo.mvID = GenreInfo.mvID
group by 
        ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname
having
        count(distinct genre) =1 and
        max(genre) = 'Action'
于 2013-10-13T12:34:19.310 回答
0

我看到您在第二个查询的 SELECT 列表中缺少 COUNT(*) 。另外,为什么第二个查询在括号中?为什么 GROUP BY 子句在查询之外?

问题是在第一个查询中你有ACtion字符串,而不是Action- 这不一样。

尝试这个:

SELECT ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname
  FROM ActorInfo, GenreInfo, CastInfo
WHERE CastInfo.mvID = GenreInfo.mvID
  AND CastInfo.ActorID = ActorInfo.ActorID
  AND Genreinfo.genre = 'Action'
MINUS
SELECT ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname
  FROM ActorInfo, GenreInfo, CastInfo
WHERE CastInfo.mvID = GenreInfo.mvID
  AND CastInfo.ActorID = ActorInfo.ActorID
  AND Genreinfo.genre != 'Action'
GROUP BY ActorInfo.ActorID, ActorInfo.firstname, ActorInfo.lastname;
于 2013-10-13T12:34:37.150 回答