• 0
Sign in to follow this  
anderson marcilio

Saldo Acumulado

Question

Olá.

Alguém poderia me ajudar em uma duvida.

no Mysql como faria para ter uma terceira coluna com o saldo acumulado por linha, como no exempo abaixo:

remessa    qtd        saldo_acumulado
1        45,1    45,1
2        47,15    92,25
3        40,75    133
4        45,2    178,2
...        ...        ...

 

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Achei a resposta.

Se tiver a mesma duvida segue a solução para o meu problema.

SELECT t1.n_remessa,t1.qtd_remessa, SUM(T2.qtd_remessa) as Soma
FROM base1 AS t1
INNER JOIN base1 AS t2 on t1.n_remessa >= t2.n_remessa
GROUP BY  t1.n_remessa,t1.qtd_remessa
ORDER BY t1.n_remessa  ASC

 

Valeu.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this