0
I wonder if there is a way to add up the values of a line with its previous.
Ex: In select below, the result I’m getting is not doing the accumulated
**SELECT DATMOV, VLRMOV, DEBCRE,
(CASE WHEN E600MCC.DEBCRE = 'C' THEN (VLRMOV) ELSE (VLRMOV * -1) END) AS RESULT
FROM E600MCC
GROUP BY DATMOV, VLRMOV, DEBCRE, E600MCC.SEQMOV, E600MCC.DEBCRE
ORDER BY DATMOV ASC**
- DatMov VlrMov DebCre Acumulado
- 20 13-11-01 00:00:00.000 15 C 15
- 2013-11-01 00:00:00.000 10 C 10
2013-11-01 00:00:00.000 -5 D -5
2013-11-01 00:00:00.000 12 C 12
2013-11-04 00:00:00.000 -20 D -20
2013-11-04 00:00:00.000 50 C 50
I wanted the accumulated column to always be the sum of the current value with the previous one.
What is the point of this GROUP BY? Search by Window Function in your DBMS.
– anonimo
https://forum.imasters.com.br/topic/585630-somar-valores-da-linha-anterior-com-a-pr%C3%B3xima/? do=findComment&comment=2285794
– Motta
Related: compare and add in sequence with sql server.
– Sorack
You did not inform the
SGBD
.– Sorack