mysql having count( 1 ) >1_MySQL-4(5个统计基础语句、having语句)

1. #  MySQL中统计函数的基础语句

sum,count,avg,max ,min

这里要注意 count(*) 和 count(1) ,在 myisam 中两者没有什么大的区别

count(column名) :计算 该column 没有null 的行数

count(*): 查询的是所有的行数的绝对值,即空值 null 也将计算在里面

tips: 在这里要把 sum、count、 avg、max、min后面当做是表达式,869218b14662781622503ec40e1dbf55.png5  个统计的基础语句

2. # having 语句及 having 与 where 的区别

having 语句 是在where语句中执行的操作后,在查询的结果的基础上重新筛选出

having 与 where 的区别;

where 是查询满足式子的所有结果

having 是在where 筛选的结果上再进行查询;

3. # 查询出商品积压的货款及积压的货款大于20000(080-having筛选 39:00)

select cate_id, sum(goods_name * goods_num) as ZHK  from goods where 1

group by cate_id having ZHK > 2000;

# 查询 出市场价格比本店价格高,且高于200以上的商品

select goods_id ,market_price,shop_price , market_price - shop_price as discount

from goods

where (market_price - shop_price > 200)   # 这里 相当于查询了2次 资源浪费

select goods_id, market_price,shop_price,market_price - shop_price as discount

from goods

having discount >200;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值