WHERE和HAVING子句之间的区别。 [英] Difference between WHERE and HAVING clause.
问题描述
我对SQL中的HAVING和WHERE子句非常困惑。
我们可以在任何地方使用HAVING吗?
我想要你 WHERE和HAVING子句之间的实际区别是什么?
我读了一篇有关此内容的代码项目文章但却无法获得实际差异。
www.codeproject.com/Articles/25258/Where-Vs-Having-Difference-between-having-and-Wher
在某处,我读到Having子句仅用于组功能而其他地方不用。
它是否真的正确?
这是唯一的区别吗?
这很简单:一个简单的选择查询在一个基集上运行,并返回与WHERE子句匹配的记录。如果使用聚合,则可以派生新的结果集,也可以对其进行过滤。对于基于聚合本身的结果进行过滤,您可以使用HAVING。
此博客文章 SQL中WHERE与HAVING子句的区别 - GROUP BY与示例的比较 [ ^ ]给出了差异的一个很好的解释。
WHERE
用于过滤单个记录和HAVING
过滤掉汇总功能 [ ^ ]使用GROUP BY
。
你可以使用 条款 GROUP BY function in 查询和 WHERE 条款 已应用 每行之前 GROUP < span BY function 查询。
I am really very confused about HAVING and WHERE clause in SQL.
Can we use HAVING wherever we use WHERE??
I want to you that "What is the actual difference between WHERE and HAVING clause"???
I read a code project article about this but not really able to get the actual difference.
www.codeproject.com/Articles/25258/Where-Vs-Having-Difference-between-having-and-Wher
Somewhere i read "Having clause is used only with group functions whereas Where is not used with."
Is it really correct??
And is this the only difference??
It is quite simple: a simple selection query runs on a base set, and returns the records that match the WHERE clause. If you use aggregation, you derive a new result set, that can be also filtered. For filtering based on the result of the aggregation itself you can use HAVING.
This blog post Difference between WHERE vs HAVING clause in SQL - GROUP BY Comparison with Example[^] gives a good explanation of the difference.
WHERE
is used for filtering the individual records andHAVING
to filter the result off an aggregate function[^] on the usedGROUP BY
.
You can use Having Clause with the GROUP BY function in query and WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
这篇关于WHERE和HAVING子句之间的区别。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!