数据库
首页 > 数据库> > sql having的使用

sql having的使用

作者:互联网

id teach_id name age
1 1 小红 13
2 1 小清 14
3 2 小d 11
4 1 小1 13
5 1 小2 14
6 2 小a 11

不使用having

SELECT * FROM (SELECT teach_id, AVG(age) AS age FROM student
 GROUP BY teach_id) t WHERE t.age > 12;

使用having

SELECT teach_id, AVG(age) AS age FROM student
 GROUP BY teach_id
HAVING AVG(age) > 12

having可以为分组设置条件

标签:age,sql,having,使用,teach,AVG,id,SELECT
来源: https://www.cnblogs.com/ococo/p/15984822.html