I am trying to find is there is an efficient way to do a query which can ignore rows of data where any column has a value of 0 or empty
My current query looks like this:
$query = "SELECT AVG(concept1) AS c1, AVG(concept2) AS c2, AVG(concept3) AS c3, AVG(concept4) AS c4, AVG(concept5) AS c5, AVG(concept6) AS c6 FROM KeyPad";
Now I dont want to count rows while averaging where any column data is 0 or null.
eg.
-----------------------------------------
|concept1 | concept2 | concept3 | ...
-----------------------------------------
| 1.2 | 3.2 | 0 | ...
| 2.4 | 4.1 | 2.1 | ...
| 3.2 | 5.1 | 2.2 | ...
| 4.3 | 3.2 | 5.3 | ...
| 1.2 | 0 | 3.2 | ...
------------------------------------------
When I run my query, I only want to generate average using data from rows 2,3,4 and ignore all data from rows 1 and 5.
I read that I can use something like COALESCE but not sure if it can work for averaging values.
Any suggestions which direction should I explore?
Additional Notes (updated):
I may not have explained correctly. When I say ignore rows, I mean if one item inn the row is 0, I want to ignore all the other items in the rows while averaging those columns too.
So in the example table above, the average for Column1 will be: (2.4+3.2+4.3) / 3 because First row in column 3 is 0 and last row in column 2 is also 0. So other columns will also need to ignore these two rows while calculating the average.
I hope that clarifies my problem.