I have a a table with a column groups INTEGER NULL. It has values
groups
5
7
<NULL>
If I do a select sum(groups) form table_name
I would get 12. How can I get null, when the column being summed has a null.
I have a a table with a column groups INTEGER NULL. It has values
5
7
<NULL>
If I do a select sum(groups) form table_name
I would get 12. How can I get null, when the column being summed has a null.
One option:
CASE WHEN COUNT(*) = COUNT(groups) THEN SUM(groups) ELSE NULL END
select
case when exists (select groups from table where groups = null) then null
else select sum(groups) from table
end as sum