On Thu, 2005-09-08 at 10:24 -0700, Will Leshner wrote: > Say I have a column called 'b' in a table called 'test' and every > field in 'b' has a NULL value. What is the expected behavior of the > following query: > > SELECT SUM(b) FROM TEST; > > I guess I'm thinking I'll get back NULL. Instead I get 0 (or, in the > 3.2.5 code, 0.0). >
SUM ignores NULLs. So if it ignores everything, it returns the sum of nothing, which is 0. (Not the 0.0 issue is fixed in CVS HEAD.) > On the other hand, the following query does return NULL: > > SELECT AVG(b) FROM TEST; > AVG is implemented as SUM/COUNT. But the count is zero. So you get a NULL. -- D. Richard Hipp <[EMAIL PROTECTED]>