结果筛选——having
# 结果筛选——having
# where
和 having
的区别
where
是对原表进行筛选,是在结果返回之前起作用的,不能使用聚合函数having
是对查询结果(结果集 / 伪表)进行过滤,可以使用聚合函数
# Example
SELECT
address,
avg( age ) AS 'avg_age'
FROM
manager
HAVING
age >= 24;
1
2
3
4
5
6
7
2
3
4
5
6
7
SELECT
classid,
count(*) AS 'num_of_student'
FROM
student
GROUP BY
classid;
HAVING
count <=10;
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
编辑 (opens new window)
上次更新: 2022/09/26, 16:55:15