Use SAFE_DIVIDE to handle division by zero.
ππΌππ_πΏππππΏπ divides two numbers while handling the case where the denominator is zero.
π Here's the syntax.
ππ΄π»π΄π²π ππ°π΅π΄_π³πΈπ
πΈπ³π΄(πππππππππ, πππππππππππ) π΅ππΎπΌ πππππππ
If the denominator is zero for any row, it returns NULL instead of causing your query to fail.
ππΌππ_πΏππππΏπ is not part of the standard SQL language, but it is often included as a custom function.
If your SQL database does not include the SAFE_DIVIDE function, you can use the CASE statement to handle division by zero. Example below!