如何避免在SQL语句中除数为零的情况

2025-04-01 14:51:34
推荐回答(2个)
回答1:

加条件分母为0直接显示0,不然就相除

select (case column1 when '0' then '0' else column1/column2 end) as a from table

回答2:

select (case when f2=0 then 0 else (f1/f2) end) from tb_name;
--一般用case when 避免