0
What would be the good practice when doing arithmetic operations that come from a database query, for example:
SELECT
valor_bruto_atual,
valor_investido,
(valor_bruto_atual / valor_investido) AS rendimento,
(valor_bruto_atual - valor_investido) AS rendimento_liquido
FROM
ativos_extratos;
In this example I only return 2 columns and 2 calculations (division and subtraction)
In this next example using the Laravel model I made a foreach going through the same query (without the calculations).
echo "<pre>";
foreach($ativos->get() as $ativo){
echo $ativo->valor_bruto_atual;
echo $ativo->valor_investido;
echo $ativo->valor_bruto_atual / $ativo->valor_investido;
echo $ativo->valor_bruto_atual - $ativo->valor_investido;
}
echo "</pre>";
dd('stop');
PHP is only illustrative, even in my test environment this example being fully functional.
Now comes the real question, what would be the best way to do these calculations, in Mysql itself or leave it to PHP to do it?
What would be the good practice for such?