查询成本 - HAVING / WHERE子句中的相关子查询

时间:2022-06-01 20:25:41

What's the difference (impact on query cost) between writing a correlated subquery in the HAVING clause rather then in the WHERE clause?

在HAVING子句中编写相关子查询而不是在WHERE子句中,有什么区别(对查询成本的影响)?

1 个解决方案

#1


1  

A WHERE-Clause is evaluated record by record whereas HAVING is evaluated per Group.

WHERE-Clause按记录进行评估,而HAVING按组进行评估。

This means. The expression in a WHERE-Clause reduces the number of rows to GROUP BY by filtering out the non-matching rows. If you do not have a WHERE Clause so all records will be used to GROUP BY. Only the last step (HAVING) filters out those groups, that doesn't meet the criteria.

这意味着。 WHERE-Clause中的表达式通过过滤掉不匹配的行来减少GROUP BY的行数。如果您没有WHERE子句,则所有记录都将用于GROUP BY。只有最后一步(HAVING)过滤掉那些不符合标准的组。

The Impact depends on your data. Filter only those rows you want to query with a WHERE-Clause and use the HAVING-Clause to filter by Aggregate-Functions.

影响取决于您的数据。仅使用WHERE-Clause过滤要查询的行,并使用HAVING-Clause按聚合函数进行过滤。

#1


1  

A WHERE-Clause is evaluated record by record whereas HAVING is evaluated per Group.

WHERE-Clause按记录进行评估,而HAVING按组进行评估。

This means. The expression in a WHERE-Clause reduces the number of rows to GROUP BY by filtering out the non-matching rows. If you do not have a WHERE Clause so all records will be used to GROUP BY. Only the last step (HAVING) filters out those groups, that doesn't meet the criteria.

这意味着。 WHERE-Clause中的表达式通过过滤掉不匹配的行来减少GROUP BY的行数。如果您没有WHERE子句,则所有记录都将用于GROUP BY。只有最后一步(HAVING)过滤掉那些不符合标准的组。

The Impact depends on your data. Filter only those rows you want to query with a WHERE-Clause and use the HAVING-Clause to filter by Aggregate-Functions.

影响取决于您的数据。仅使用WHERE-Clause过滤要查询的行,并使用HAVING-Clause按聚合函数进行过滤。