Doubt with calculation of the profit margin between values

Asked

Viewed 596 times

1

I have an 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'

inserir a descrição da imagem aqui

  • What is the question? Ask the question

1 answer

1

ai is math, (higher / lower) -1 * 100

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

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

that is, bought for 50,00 , sold for 100,00 , had 100% profit. what you’ll have to do is take the final sales value, the cost value total you had to buy this merchandise, then just do the bill above, however as you have several products and each with its cost, or calculates one by one, or sums everything up and does the above account, will have an average.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.