sql >> Base de Datos >  >> RDS >> Mysql

Cómo manejar condicionalmente la división por cero con MySQL

Sí, puedes hacer un caso:

select case when noOfGirls=0 then noOfBoys 
       else  round(noOfBoys/noOfGirls) end as ration 
from student;

Pero probablemente quieras:

select case when noOfGirls=0 then 1 
       else  round(noOfBoys/noOfGirls) end as ration 
from student;