这是数据库架构:
哪个查询首次返回每位影星在电影中加星标的年龄?不应列出任何电影是否属于任何电影的明星。
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
。但我不知道其他三个中哪一个是正确的。我很感激每个查询的解释。