日期:2014-05-17  浏览次数:20870 次

一个函数的小问题!如何求非零平均数~
我想做求1组数的平均值,但是如果其中一个数是零就不参加计算。
需要怎么写呢?似乎很简单。就是不会,呵呵!
各位谁会帮帮忙。谢谢!30分笑纳~

------解决方案--------------------
select case when t.num <> 0 then avg(t.num) end from table t
------解决方案--------------------
用函数nvl
欢迎加入oracle qq群9701750
------解决方案--------------------
直接用条件把等于0的过滤掉然后用AVG函数不就可以了
select avg(col) from table where col<> 0
------解决方案--------------------
探讨
直接用条件把等于0的过滤掉然后用AVG函数不就可以了
select avg(col) from table where col <> 0

------解决方案--------------------
探讨
直接用条件把等于0的过滤掉然后用AVG函数不就可以了
select avg(col) from table where col <> 0

------解决方案--------------------
用decode函数处理下再avg。
with t as (
select 20 id from dual
union all
select 30 from dual
union all
select 0 from dual
union all
select 40 from dual
union all
select 110 from dual
union all
select 0 from dual
)
select avg(decode(id,0,null,id)) from t;