鉴于此数据库架构:
以下两个查询之间是否存在差异:
SELECT NAME, MIN(MOVIEYEAR - YEAR(BIRTHDATE)) AS DEBUT_AGE
FROM STARSIN
JOIN MOVIESTAR ON STARNAME = NAME
GROUP BY NAME;
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);
我认为他们会返回相同的结果,我错了吗?
答案 0 :(得分:0)
第二个中的HAVING条件不完整。 第二个也跳过Movieyear为NULL的任何行,而第一个没有处理(当然这可能是多余的,具体取决于Movieyear是否为Nullable)