SUM for columns with null values
The column contains both values and missing values. Will SUM function work for such columns by ignoring those null values?Thanks.
1 answers ( 0 marked as helpful)
Hi Christine Li!
Thanks for reaching out.
In MySQL, SUM()
is supposed to ignore null values. In any case, if you want to be specific, you can instruct the SQL Optimiser to substitute the null values with the value of 0. To do that, you can help yourself with the COALESCE() function and the following model:
SELECT COALESCE(SUM(column_name), 0)
...
Hope this helps.
Best,
Martin