On Tue, May 22, 2001 at 12:29:35PM -0400, Graeme B. Davis wrote:
> Is there a way to get the AVG of all specified NON-NULL columns in one row?
> Right now I am doing this in a little script, but it would be nice if I
> could do something like this:
> 
> DATA
> ---------
> id1    0    4    4    NULL    3    NULL
> 
> I want the average of 0,4,4,3 ie (0+4+4+3)/4
> 
> is there a way to do this in a SELECT query?

SELECT SUM(field) / COUNT(field)
FROM table
WHERE othercondition AND (field IS NOT NULL)

G'luck,
Peter

-- 
I am the meaning of this sentence.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to