SQL 查询 - 查找完全在同一部电影中扮演过的所有演员

SQL query - Find all couples of actors who has played EXACTLY in the same movies

我正在为即将进行的数据库考试练习,但我不知道如何进行此查询。

我按原样复制粘贴练习: 给定 2 个表

FILM(Title, Director, Year, Genre)
InCastOf(Actor, Film) Where InCastOf(film) is constrained to Film(Title)

编写查询以查找完全在同一部电影中扮演过的所有演员夫妇。

到目前为止我得到的是:

SELECT InCastOf.Actor AS A1, T.Actor AS A2, InCastOf.Film FROM InCastOf
JOIN (SELECT Actor, Film FROM InCastOf) AS T ON InCastOf.Film = T.Film
WHERE  InCastOf.Actor != T.Actor

其中returns我为每部电影配了一对演员。我可以使用 group by etc 来确定查询,但是 "Exactly" 这个词给我带来了一些麻烦,因为我需要确保这些演员只在同一部电影中工作,而没有其他。至少我是这么理解"Exactly"这个词的。

感谢您的帮助!

感谢@Martin Smith 的提示,我编写了如下查询:

SELECT T1.Actor AS A1, T2.Actor AS A2, T1.films FROM (
    SELECT Actor, GROUP_CONCAT(Film) AS films
    FROM InCastOf 
    GROUP BY Actor) AS T1
JOIN (
    SELECT Actor, GROUP_CONCAT(Film) AS films
    FROM InCastOf 
    GROUP BY Actor) AS T2 
ON T1.films = T2.films
WHERE T1.Actor > T2.Actor