I have a long sql query that calculates a few things about payments and shipments. In some cases the value is null. I think that’s because there’s being divided by 0.
Here’s a small part of my query:
ROUND(sum(case when shipping_method = 'c' AND (paid_amount - shipping_costs) < 70 then 1 end) * 100 / sum(case when shipping_method = 'c' then 1 end),2) as co_less_70,
I think that when this part is 0: sum(case when shipping_method = 'colissimo' then 1 end),2) my query shows null. Is there any way to assign a default value for this co_less_70 column?
Yes. You can use the
COALESCE()function:In your code: