关于where和having的直观理解

一,查询区别

where是对前面select的字段没有要求,直接查询库表的

having是对前面的select的字段有要求,字段已经select出来的 可以用having进行处理 

select id,good from test where price>0

select id,good from test  having price>0  having会报错

二,聚合区别

where 可以对数据库的字段,直接进行查询,组装,但是对聚合后的结果不能处理

having 可以对聚合后的结果处理

select sum(price) as tprice from test where tprice>0  where报错

select sum(price) as tprice from test having tprice>0

原文地址:https://www.cnblogs.com/baker95935/p/8780242.html