having 和where 的区别

having 关键字 可以接聚合函数 出现在分组(group by)之后(只能在分组之后用)
where 关键字 它是不可以接聚合函数,出现在分组之前 --都是做条件的过滤

根据no分组。分组后统计每组商品的平均价格 并且价格>60

select     no,avg(price)   
from  prouduct   group   by   no
having   avg (price) >60

编写顺序
S…F…W…G…G…O
select … from … where …group by … having … order by

执行顺序
from… where… group by… having… select … order by

delete 与 truncate 区别
delete from 表名 where
truncate table 表名 :先删除 表,再重建表

猜你喜欢

转载自blog.csdn.net/qq_42435514/article/details/83382475