WHERE语句在GROUPBY语句之前;SQL会在分组之前计算WHERE语句。
HAVING语句在GROUPBY语句之后;SQL会在分组之后计算HAVING语句。
例子一
SELECT ProductID
FROM Sales.SalesOrderDetail
GROUP BY ProductID
HAVING AVG(OrderQty) > 5
ORDER BY ProductID ;
例子二
select center
from materials_10
group by center
having count(material) <> count(distinct material)#重复元素
;