MySQL: AVG in SELECT
| From: | Tom Churm | Date: | Thu, 11 Oct 2001 09:08:46 +0000 |
| Subject: | MySQL: AVG in SELECT | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-70764@lists.php.net to get a copy of this message | ||
hi,
i have a select statement to give me the averages for various mysql
columns. for one of the columns, i need to take the average for only
those fields where the content !='6' (with 6 being a Flag telling me
to exclude it). so i came up with the following
select statement, which returns no mysql_error, but does not return the
correct figure for the AVG:
SELECT AVG(q1), AVG(q2), AVG(q3), AVG(q4), AVG(q5), AVG(q6), AVG(q7),
AVG(q8), AVG(q11), AVG(q16), AVG(q18!='6') FROM hr_form2 WHERE Answer !=
0
from this i should get a return of something like this, since NONE of my
fields in column q18 contain a '6':
AVG(q18) = 2.7143
instead, i get this:
AVG(q18) = 1.0000
could someone please tell me--is there a logical error in my thinking
here? i want to select the AVG from q18 ONLY for those fields where
q18!=6 : for those fields where q18=6, I just want it left out of the
AVG.
there's definitely a better way to formulate my sql, right?
muchos gracias,
tom