Calcular saldo acumulado

Everton Santos 1 Reputation point
2022-04-09T19:41:09.89+00:00

Olá Galera, Gostaria de calcular o saldo acumulado em cada movimentação. por exemplo; Produto saida entrada saldo saldo acumulado MARGARINA 16 0 -16 -16 MARGARINA 8 0 -8 -24 SELECT Produto, SUM(CASE WHEN tipo_mov = 'saida' THEN Quantidade ELSE 0 END) AS saida, SUM(CASE WHEN tipo_mov = 'entrada' THEN Quantidade ELSE 0 END) AS entrada, SUM(Quantidade * CASE WHEN tipo_mov = 'entrada' THEN 1 ELSE - 1 END) AS soma FROM dbo.Movimentacao WHERE Produto ='Margarina' GROUP BY Produto, Data_Lancamento ORDER BY soma ![191571-image.png][1] [1]: /api/attachments/191571-image.png?platform=QnA

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,143 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dave Patrick 426.4K Reputation points MVP
    2022-04-09T20:01:22.867+00:00

    Q&A forums are currently English only. I'd try asking for help over here in dedicated forums.
    https://social.msdn.microsoft.com/Forums/pt-br/home
    https://social.technet.microsoft.com/Forums/pt-br/home
    https://answers.microsoft.com/pt-br

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments