"Jay Blanchard" <[EMAIL PROTECTED]> wrote on 12/16/2004 
01:00:00 PM:

> [snip]
> Is there any way to make sum() return "0" instead of "NULL" when one or
> more of the rows being sum()'d is null?
> 
> Phrased another way, is there a way to make mySQL treat "NULL" as "0"
> when dealing with mathematical functions?
> [/snip]
> 
> Use an IF...
> 
> SELECT SUM(IF(myColumn IS NULL, 0, myColumn)) AS myTotal
> FROM myTable


alternatively:

SELECT SUM(COALESCE(myColumn,0)) as myTotal

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Reply via email to