一、where跟的字段是表中真实存在的字段,例如:
1、select age,name from dw_users where age> 15
2、select age,name from dw_users having age> 15 //报错!!!因为前面并没有筛选出age字段
age是真实存在的字段,
二、having后面跟的字段是聚合函数(avg,count,sum)的字段
1、select category_id , avg(price) as ag from dw_goods group by goods_category having ag > 100
2、select category_id , avg(price) as ag from dw_goods where ag>100 group by goods_category //报错!!因为from dw_goods 这张数据表里面没有ag这个字段
ag是avg(price) as ag中的别名字段,不是表真实字段,所以条件过滤时只能用having