[thelist] Calculating weighted averages

Bill Moseley moseley at hank.org
Sat Jul 14 16:55:13 CDT 2007


On Sat, Jul 14, 2007 at 04:13:03PM -0400, r937 wrote:
> if a student has not taken a particular exam, there will be no row in the 
> test table for that student for that exam
> 
> thus, since it's a LEFT OUTER JOIN, all columns from the test table in the 
> query will be null for this situation
> 
> consequently, computation involving test.score will be null too


That's what I was hoping for.  But,

=> select * from foo; i  
----
 23
 50

(3 rows)

Note last row is NULL.

> select AVG( i ) from foo;
         avg         
---------------------
 36.5000000000000000
(1 row)

So if one row is NULL AVG() is acting on just the non-null rows.


-- 
Bill Moseley
moseley at hank.org




More information about the thelist mailing list