-1
Movie(title, year, director, budget, earnings)
Actor(stagename, realname, birthyear)
ActedIn(stagename, title, year, pay)
CanWorkWith(stagename, director)

找到所有成对的艺名(重命名为 stagename1 和 stagename2),使得 stagename1 的演员与 stagename2 的演员在同一部电影中表演,但在该电影中表演的收入较少。

SELECT A.stagename, B.stagename
FROM ActedIn A
LEFT JOIN ActedIn B ON A.title = B.title AND A.year = B.year
          AND B.pay > A.pay
WHERE B.name IS NOT NULL

不确定 WHERE B.name IS NOT NULL 是否有效

4

2 回答 2

2

http://sqlfiddle.com/#!2/67568/1

select a1.stagename as stagename1, a2.stagename as stagename2, a1.title
from ActedIn as a1
 inner join ActedIn as a2 on (a1.title = a2.title and a1.year = a2.year)
where a1.pay < a2.pay
于 2012-06-14T03:58:17.333 回答
1
SELECT A.stagename, B.stagename
FROM ActedIn A
INNER JOIN ActedIn B ON A.title = B.title 
AND A.year = B.year AND B.pay > A.pay
WHERE B.name IS NOT NULL

如果您不想要 B 的 NULL 值,则 LEFT JOIN 将毫无用处。

于 2012-06-14T03:53:29.693 回答