-
xsmile replied to the topic "SQL学习中的一些问题" – 4年, 11个月前
参考:https://zhidao.baidu.com/question/262780155.html1.类型:“Where”是一个约束声明,在查询数据库的结果返回之前对数据库中的查询条件进行约束,即在结果返回之前起作用,且where后面不能使用“聚合函数”;“Having”是一个过滤声明,所谓过滤是在查询数据库的结果返回之后进行过滤,即在结果返回之后起作用,并且having后面可以使用“聚合函数”。2.使用的角度:where后面之所以不能使用聚合函数是因为where的执行顺序在聚合函数之前,如下面这个sql语句:select sum(score) from student group by student.sex where sum(student.age)>100;having既然是对查出来的结果进行过滤,那么就不能对没有查出来的值使用having,如下面这个sql语句: select student.id,student.name from student having student.score >90;