Subject Re: [firebird-support] How write a query with a progressive sum field
Author Luigi Siciliano
Il 07/03/2016 11.58, Dimitry Sibiryakov sd@...
[firebird-support] ha scritto:
> sum(carcio-scarcio) over (<whatever you need>) as SALDO.

Ok, I understand but, "over" is unknow in firebird 2.5.5.

I modified my query like this:

select
DT.DATA,
DT.DOCUMENTO_ID,
DT.NUMERO,
DT.SERIE,
DC.CARICO,
DC.SCARICO,
SUM(dc2.carico - DC2.SCARICO) AS saldo
from
DOC_TESTA DT
JOIN DOC_CORPO DC on DT.ID = DC.DOC_TESTA_ID
left JOIN DOC_CORPO DC2 ON (DC.DOC_TESTA_ID >= DC2.DOC_TESTA_ID)
AND (DC.ARTICOLO_ID = DC2.ARTICOLO_ID)
WHERE
DC.ARTICOLO_ID = :ID
GROUP BY
DATA,
DOCUMENTO_ID,
NUMERO,
SERIE
ORDER BY
DATA,
DOCUMENTO_ID,
NUMERO,
SERIE

but I have an issue:

if I have a row with CARICO = 0 and SCARICO = 0

then SALDO is added or subtracted of number present in last row with
CARICO > 0 or SCARICO > 0

Thanks
--

Luigi Siciliano
--------------------------