• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate average, ignore zero ('0')?

#1
[eluser]mvdg27[/eluser]
Hey guys,

not directly CI related .. but does anyone know how to calculate the average of a column, but ignoring the zero values?

So imagine: 10, 8, 6, 0, 4 => average = 28 / 5 = 5.6

Instead I would like: 10, 8, 6, 0 (ignore this value!), 4 => average = 28 / 4 = 7

I'm using MySql.

Thanks, Michiel

#2
[eluser]Dam1an[/eluser]
This should do it
just select anything greater then 0 for the AVG
Code:
SELECT AVG(`number`) FROM test WHERE `number` > 0

#3
[eluser]renownedmedia[/eluser]
Maybe use NULL's instead of 0's


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.