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 is null) then null
else select sum(groups) from table
end as grp_sum
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With