壹:
where后面不能跟聚合函数(sum、avg、count、max、min)
having后面可以跟
贰:
where和having都能用:
select goods_price,goods_name from sw_goods where goods_price>100
select goods_price,goods_name from sw_goods having goods_price>100
原因:goods_price作为条件也出现在了查询字段中。
只能用where:
select goods_name,goods_number from sw_goods where goods_price>100
select goods_name,goods_number from sw_goods where goods_price>100(X)
原因:goods_price作为筛选条件没有出现在查询字段中,所以就会报错。
只能用having 的:
select goods_category_id,avg(good_price) as ag from sw_goods group by goods_category having ag>1000
select goods_category_id,avg(goods_price) as ag from sw_goods where ag>1000 group by goods_category(X)报错,这个表里没有这个ag这个字段。