我试图了解 HAVING 和 WHERE 之间的区别。我知道这HAVING与 GROUP BY 语句一起使用。但是,我不明白为什么接受以下声明:
HAVING
select SUM(child_id) from children WHERE child_ID = 5 GROUP BY Child_ID
不应该是正确的说法select SUM(child_id) from children GROUP BY Child_ID HAVING child_ID = 5吗?
select SUM(child_id) from children GROUP BY Child_ID HAVING child_ID = 5
WHERE 子句在分组过程发生之前执行,并且只能访问输入表中的字段。HAVING 在分组过程发生后执行,可以根据分组过程中计算的聚合值的值过滤结果。