Luigi Siciliano luigi...@tiscalinet.it [firebird-support] wrote:
I get exception: "invalid expression in the select list (not contained in either an aggregate function or the group by clause)". I don't understand the GROUP BY clause who I need to write in sub-select because if I put the same as in select: "GROUP BY DATA, DOCUMENTO_ID, NUMERO, SERIE" I get the exception: "cannot use an aggregate function in a GROUP BY clause."
I'm confused :(
Yeah, I wonder why that worked in the first place in your original select. You didn't group by DC.CARICO and DC.SCARICO there too.

But with a (SELECT)-field you don't need to group anymore.

Try this:

select
  DT.DATA,
  DT.DOCUMENTO_ID,
  DT.NUMERO,
  DT.SERIE,
  DC.CARICO,
  DC.SCARICO,
  (SELECT SUM(DC2.CARICO - DC2.SCARICO) FROM DOC_CORPO DC2
   WHERE (DC2.DOC_TESTA_ID = DT.ID) AND (DC2.ARTICOLO_ID = DC.ARTICOLO_ID)
   AND (DC2.DOC_TESTA_ID <= DC.DOC_TESTA_ID)
  ) AS SALDO
from DOC_TESTA DT
JOIN DOC_CORPO DC on DC.DOC_TESTA_ID = DT.ID
WHERE DC.ARTICOLO_ID = :ID
ORDER BY DT.DATA, DT.DOCUMENTO_ID, DT.NUMERO, DT.SERIE

              • ... Dimitry Sibiryakov s...@ibphoenix.com [firebird-support]
              • ... Thomas Steinmaurer t...@iblogmanager.com [firebird-support]
              • ... 'Leyne, Sean' s...@broadviewsoftware.com [firebird-support]
              • ... Lester Caine les...@lsces.co.uk [firebird-support]
              • ... 'Carlos H. Cantu' lis...@warmboot.com.br [firebird-support]
      • Re: [... Thomas Steinmaurer t...@iblogmanager.com [firebird-support]
        • R... 'Leyne, Sean' s...@broadviewsoftware.com [firebird-support]
        • R... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
          • ... r...@graficalc.nl [firebird-support]
            • ... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
              • ... Rik van Kekem r...@graficalc.nl [firebird-support]
    • Re: [fire... Mark Rotteveel m...@lawinegevaar.nl [firebird-support]
  • Re: [firebird-... setysvar setys...@gmail.com [firebird-support]
    • Re: [fire... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]

Reply via email to