List:General Discussion« Previous MessageNext Message »
From:Jay Blanchard Date:December 16 2004 6:00pm
Subject:RE: sum() Function and NULL values
View as plain text  
[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
Thread
sum() Function and NULL valuesTim Gustafson16 Dec
  • Re: sum() Function and NULL valuesJohan Höök16 Dec
  • Re: sum() Function and NULL valuesbeacker16 Dec
RE: sum() Function and NULL valuesJay Blanchard16 Dec
  • RE: sum() Function and NULL valuesSGreen16 Dec
RE: sum() Function and NULL valuesTim Gustafson17 Dec