At http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html
I read:

   The AVG function computes the average of values in
   a column or an expression.  SUM computes the sum.
   Both functions ... ignore NULL values.

PostgreSQL docs say that NULL is returned if all inputs
to sum are NULL.

So then, if there are no input rows at all (if no rows
match the WHERE clause) then SUM returns 0.  (This makes
sense because if you say:

    SELECT sum(amt) FROM sales WHERE month='october';

and you didn't sell anything in October, you want an
answer of 0, not NULL.)  Or if *some* of the entries are
NULL, then the answer is the sum of the non-NULL entries.
But if the number of entries is greater than zero and
they are all NULL, then the answer is NULL.

Logical, right????

The more I learn about NULLs in SQL the less sense they
make...
-- 
D. Richard Hipp <[EMAIL PROTECTED]>

Reply via email to