This may be due to the fact, that the latter has a where clause.If you show what VonBisAlsString, KontowahlOhneWHERE and s are, maybe we can tell.
How to do it better?
How to put it, that SUM does only sum up results, which MATCH the where clause?In that case you also need to do the same WHERE in the subselect (for SUM).
Works fine in postgres@Nicole didn't show the WHERE from the main SELECT.
If you do a WHERE there the numbers might not add up correctly anymore (because the total sum until that date is always taken).
using d4eva's dataLooks easier on the eyes...
SELECT id_trade,EXIT_DATE,ergebnis, SUM(ergebnis) OVER(ORDER BY exit_date) AS Summe FROM tbtrades ORDER BY EXIT_DATE
Mmm, that was for Firebird 3.But it should: https://www.firebirdsql.org/file/documentation/html/en/refdocs/fblangref40/firebird-40-language-reference.html#fblangref40-windowfuncs
Firebird 4 doesn't seem to like it:
https://dbfiddle.uk/EFZVHCHc
It doesn't like the Numeric-Datatype for Summing?!?!?!?Yikes. In Firebird 3 it did work.
"Ergebnis" changed to integer. works immediately
Yikes. In Firebird 3 it did work.
Maybe the size 12,2 is too big.
Weird.
Edit: Yes. NUMERIC(9,2) works. From NUMERIC(10,2) onwards it fails.
https://dbfiddle.uk/KL_Ei2pf
If you do a WHERE there the numbers might not add up correctly anymore (because the total sum until that date is always taken).
What exactly is the problem now?
( )
and: no, moving the ")" down, does not solve it.
This SQL statement is legacy from Firebird 2.5. In the meanwhile I upgraded to Firebird 4.0.
So there may be an advanced way to put it (which I do not know how to), which Firebird 2.5. would not have accepted.