SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
有和哪里有什么区别
答案 0 :(得分:8)
where
过滤器
select ... from
过滤了having
所以,再看一遍你的例子:
group by ...
此处,SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value
表示“返回table_name所在的结果
'column_name operator value'为true“。
只有在找到这些条件的所有结果后,才按列名分组。
然后WHERE column_name operator value
说“对于生成的聚合组,运行'aggregate_function(column_name)'并仅返回'aggregate_function(column_name)运算符值'为真的结果。”
答案 1 :(得分:7)