从整体声明角度分析:

  “where”是一个约束声明,在查询数据库结果返回之前对数据库的查询条件做一个约束,即返回结果之前起作用,“where”后面不能跟聚合函数;

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

  “having”是一个过滤声明,在查询数据库结果返回之后进行过滤,即返回结果之后起作用,“having”后面可以加聚合函数;

聚合函数:是对一组值进行计算,返回单一的值,例如:count(),sum(),max(),min()

从使用角度分析:

  “where”   select  student_id,student_name from student where student_sorce>80;

  "having"  select sum(sorce) from student group by student_sex having student_id<10;

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄