0

我一直试图找出教程中第 13 个问题的正确 SQL。其他问题都与我无关,只有#13。

本质上,问题是找出“朱莉·安德鲁斯”出演的所有电影,并从结果中选择在这些电影中扮演主要演员的演员。听起来很简单,但我尝试的一切都失败了。以下:

select title, name from movie
  join casting on movie.id=movieid
  join actor on actorid=actor.id
  where (name = 'Julie Andrews' ) 
  and ord=1

选择她参演的电影,她是男主角。我需要的是她参演的电影的主角,而不是她主演的电影。

有没有人有什么建议?

4

2 回答 2

0
select movie.title, actor.name
from movie, actor, casting, (SELECT movieid from casting join actor 
on actor.id=casting.actorid where actor.name = 'Julie Andrews') JAM
where movie.id = JAM.movieid and actor.id = casting.actorid
and casting.movieid=JAM.movieid and casting.ord=1
group by movie.title
于 2013-11-13T07:37:35.960 回答
0

尝试这个:

select m.title, a.name
from movie m
join casting c on m.id = c.movieid
   and ord = 1
join actor a on a.id = c.actorid
where exists (select *
   from casting c2
   join actor a2 on c2.actorid = a2.id
      and a2.name = 'Julie Andrews'
   where c2.movieid = m.id
)
于 2013-11-13T18:19:07.477 回答