Subject Re: Best table structure for Debit/Credit
Author Scott Moon
--- In firebird-support@yahoogroups.com, Matthias Hanft <mh@...> wrote:
> Whenever I insert the following section for the "current_
> reminders" result column:
>
> > SUM(
> > case
> > when b.transtype = 'R'
> > and NOT EXISTS(select * from billing b2
> > where b2.custno = b.custno
> > and b2.transtype = 'P'
> > and b2.transdate >= b.transdate)
> > then 1 else 0 end) as current_reminders
>
> I get this error message:
>
> Dynamic SQL Error
> -SQL error code = -104
> -Invalid expression in the select list (not contained in either an
aggregate function or the GROUP BY clause)
>
> If I remove that section, the query runs fine again.

That error generally means that you've left one or more non-aggregated
SELECTed fields out of your GROUP BY clause. For example:

SELECT fieldA, SUM(fieldB), fieldC
FROM sometable
GROUP BY fieldA /* omitting fieldC */

...will produce that error. Adding fieldC to the GROUP BY clause would
fix it.

Scott