-1
I need to update a column according to the contents of the other two columns, for example, I have two tables, the table suprimentos
and the table estoque
,
Table supplies
codigoSuprimento
capacidadeSuprimento
Stock Table
codigoSuprimento
capacidadeUsada
percentualUsado
Let’s say on the table suprimentos
i own the following register:
codigoSuprimento | capacidadeSuprimento
1 | 1000
And on the table estoque
the following register:
codigoSuprimento | capacidadeUsada | percentualUsado
1 | 300 | X
My need is to create a Function so that the column percentualUsado
is completed in accordance with capacidadeUsada
on top of capacidadeSuprimento
. Seria capacidadeUsada
x 100
/ capacidadeSuprimento
. But I don’t know how to do it in a Function, put this content in parameters to be able to perform this calculation which is an unknown to me.
Explain one thing to me, you could not do subselect for Stock table insertion, Example:
INSERT INTO estoque (codigoSuprimento,capacidadeUsada,percentualUsado)
(1,300,(SELECT 300*100/(capacidadeSuprimento) FROM suprimento WHERE codigoSuprimento = 1))
this is just a small example, so you can better organize your reasoning line.– Marcus Italo
@Marcusitalo, thanks for the tip, but yesterday analyzing my need, I realized that there would be no need to know the percentage that the supply was used because knowing the used capacity already solves my problem, sometimes it is necessary to just blur a little of the problem to find that the answer is right in the face, but again thanks for the tip
– R.Santos