去掉空值算平均数 SELECT AVG(price) as price from data_1 where请问要去掉计算所有空值(0)的平均数该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SELECT AVG(price) as price from data_1 where IFNULL(price,0)>0 0 不是空值 SELECT AVG(price) as price from data_1 where price<>0 where price is not null; 不明白楼主的意思你是不是想这样,比如说你的表t_test里只有一个字段,就叫price,里面有5行数据,比如他们的值为1,2,3,null,5.你是不是想计算平均值的时候,得到的数据是这样的(5+3+2+1)/5 ? 也就是说,有5行数据,但是只有4个有值,但你想计算出他们的值对5个的平均值?如果这样 select avg(price) from t_test 得到的数是2.7500这是(5+3+2+1)/4的结果如果你想要让他平均给5行数据的话,这样select avg(a.price) from (select coalesce(price,0) as price from test) a,得到的数是2.2000OK!搞定 SELECT AVG(price) as price from data_1 where price<>0 and price is not null双重啊? SELECT AVG(price) as price from data_1where price=0 or price is null;-- 这么简单的问题也来问,你还能做什么? SELECT AVG(price) as price from data_1where price<>0 or price is not null; 10楼的代码还是有问题,or应该改为and MySQL死锁:Lock wait timeout exceeded; try restarting transaction mysql数据汇总 求一条sql语句 菜鸟问题 急........mysql 存储过程问题 mysql不支持 同台机器两个mysql数据库之间做触发器??? ./configure mysql的问题? 哪里有64位的MYSQL下载呀?急用哟~! mysql root问题 错误1044怎么解决 初学mysql,问下如何通过外键实现1对多的关系 遇到一个奇怪的问题(mysql查询),真的好奇怪呀。
SELECT AVG(price) as price from data_1 where price<>0
如果这样 select avg(price) from t_test 得到的数是2.7500
这是(5+3+2+1)/4的结果
如果你想要让他平均给5行数据的话,这样
select avg(a.price) from (select coalesce(price,0) as price from test) a,得到的数是2.2000
OK!搞定
双重啊?
where price=0
or price is null;-- 这么简单的问题也来问,你还能做什么?
where price<>0
or price is not null;