D. Richard Hipp wrote:

Can somebody come up with a realistic scenario where they would
actually want SUM() to return NULL instead of 0?
I have found that, when dealing with NULL values, it helps to think of a Null as "I don't know, I have no data".
So, if the where clause returns no records, I do know the result: It is 0.
If there where clause returns records with NULL values, that means I did not know the values and so can
not know the sum, too. Sum() should therefore return NULL.
When I want to regard a NULL value as 0 in this (or any) context, I use a sum(coalesce(row, 0)).

Martin

Reply via email to