0
I have a product table and I want to calculate the profit margin based on the columns preco_venda
and preco_custo
I did as below:
update produto set margem_lucro=((((preco_unit/preco_custo)*100)-100))
The mistake happens
ERROR: Division by zero
ERROR: Division by zero SQL state: 22012
What is wrong?
In some line the value of preco_cost must be zero , it cannot be divided by zero, update product set margem_profit= (case when preco_product > 0 then (((preco_unit/preco_cost)*100)-100)) Else null end)
– Motta
update produto set margem_lucro= (case when preco_custo > 0 then (((preco_unit/preco_custo)*100)-100)) Else null end) that’s right, I did as you said and worked, Motta was worth!
– Ronailson Gomes
@Motta, as an answer
– Denis Rudnei de Souza
update product set margem_lucro= (case when preco_custo > 0 then (((preco_unit/preco_custo)*100)-100)) Else null end) that’s right, I did as I said and worked, it was worth @Motta!
– Ronailson Gomes
update product set margem_lucro= (case when preco_custo > 0 then (((preco_unit/preco_custo)*100)-100)) Else null end) that’s right, I did as I said and worked, it was worth @Motta
– Ronailson Gomes