Doubt with calculation of the profit margin between values

0

I have a sql query where I am showing the cost value and sales value of the product, I would like to show the profit margin between cost and sales values, for the quantity of items sold

select 
a.RAZAO_SOCIAL,
d.CODIGOCOMERCIAL,
d.DESCRICAO AS NOME_PRODUTO, 
c.ESTOQUE_ATUAL,
d.PRECO_CUSTO,
d.PRECO_VENDA,
e.QTDITENS AS SAIDA_PRODUTO,
(c.ESTOQUE_ATUAL + e.QTDITENS) as COMPRAS,
e.IDEMPRESA AS CLIENTE_VENDA,
(e.QTDITENS * D.PRECO_VENDA) - (e.QTDITENS * D.PRECO_CUSTO)  AS LUCRO_BRUTO,
C.DATA_ESTOQUE_ATUAL
from
TB_EMPRESA a
inner join TB_ESTOQUE b on a.IDEMPRESA = b.IDEMPRESA 
inner join TB_ESTOQUE_PRODUTO c on b.IDESTOQUE = c.IDESTOQUE
inner join TB_PRODUTO d on c.IDPRODUTO = d.IDPRODUTO
left outer join TB_MOVIMENTO_ESTOQUE e on c.IDESTOQUEPRODUTO = e.IDESTOQUEPRODUTO
where a.EMPRESA_CLIENTE = 'N'

    
asked by anonymous 30.10.2017 / 18:22

1 answer

0

ai is mathematics, (major / minor) -1 * 100

example, cost R $ 50,00, sale R $ 100,00

(100/50) -1 * 100, -> (2) -1 * 100, -> (1) * 100 = 100% (result)

ie bought for 50.00, sold for 100.00, had 100% profit. what you will have to do is take the final value of the sales, the cost amount total amount you had to buy this merchandise, then it is only to make the account above, but as you have several products and each one with its cost, or calculates one by one, or sum all and does the above account, it will have an average.

    
30.10.2017 / 19:01