我应该使用哪个查询来获取每个电影明星首次在电影中出演的年龄?

时间:2014-09-09 08:15:37

标签: sql

这是数据库架构:

enter image description here

哪个查询首次返回每位影星在电影中加星标的年龄?不应列出任何电影是否属于任何电影的明星。

A: SELECT NAME, MIN(MOVIEYEAR) - YEAR(BIRTHDATE) AS DEBUT_AGE
   FROM MOVIESTAR
   NATURAL JOIN STARSIN ON NAME = STARNAME
   GROUP BY NAME;

B: SELECT NAME, MIN(MOVIEYEAR - YEAR(BIRTHDATE)) AS DEBUT_AGE
   FROM STARSIN
   JOIN MOVIESTAR ON STARNAME = NAME
   GROUP BY NAME;

C: SELECT NAME, MOVIEYEAR - YEAR(BIRTHDATE) AS DEBUT_AGE
   FROM MOVIESTAR
   LEFT JOIN STARSIN ON NAME = STARNAME
   WHERE MOVIEYEAR IS NOT NULL
   GROUP BY NAME
   HAVING MIN(MOVIEYEAR);

D: SELECT DISTINCT MS.NAME, MOVIEYEAR - YEAR(BIRTHDATE) AS DEBUT_AGE
   FROM MOVIESTAR MS, STARSIN
   HAVING MS.NAME = STARNAME
          AND MOVIEYEAR <= ALL (SELECT MOVIEYEAR
                                FROM STARSIN SI
                                WHERE SI.STARNAME = MS.NAME);

我知道D不是答案,因为我们HAVING没有GROUP BY。但我不知道其他三个中哪一个是正确的。我很感激每个查询的解释。

0 个答案:

没有答案