Having子句允许指定条件来过滤将出现在最终结果的分组结果。
WHERE子句在所选列上设置条件,而Having子句则在由Group By子句创建的分组这是条件。
语法#
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
SELECT column1, column2
FROM table1, table2
WHERE [conditions]
GROUP BY column1, column2
HAVING [conditions]
ORDER BY column1, column2
实例#
样例表SELECT * FROM COMPANY GROUP BY name HAVING count(name) < 2;
网友评论