mysql五大子句中where和having两个过滤使用区别

2025-06-08 01:15:20

1、having子句的作用和where类似,都是具有根据条件对数据进行过滤的作用,不同点在于having在group by之后,而where在group by之前,另外where是先过滤后聚合,having是先聚合后过滤

2、以mysql系统自带ecs_goods表为例,要求提取:索爱C702c'及其shop_price总和,分别用having和where求出同样的结果。

mysql五大子句中where和having两个过滤使用区别
mysql五大子句中where和having两个过滤使用区别

3、having查询方法:select goods_name,sum(shop_price) as price from ecs_goods group by goods_name having goods_name='索爱C702c'';

mysql五大子句中where和having两个过滤使用区别

4、where查询方法:select goods_name,sum(shop_price) as price from ecs_goods where goods_name='索爱C702c';

mysql五大子句中where和having两个过滤使用区别
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢