Subject Re: Invalid expression in the select list (not contained in ..) FB problem?
Author Pavle
--- In firebird-support@yahoogroups.com, "karolbieniaszewski" <liviuslivius@...> wrote:
>
>
> --- In firebird-support@yahoogroups.com, "Pavle" <pavle.grebenar@> wrote:
> >
> > ... and there is no need for group by at all
> >
>
> grouping is needed
> without grouping this query will run against each row ..
>
yes, same table (Doc_Mag), sorry... but there is no agregate function on DM level
maybe distinct mag_id, year, month without group by clause gives same efect like:

execute block
returns (
mag integer; -- ID
y smalint;
m smallint;
ss decimal(18,4)
)
as

begin
for select distintc dm.id_mag,
extract(year from dm.data_doc),
extract(month from dm.data_doc)
from Doc_Mag dm
into :mag, :y, :m
do select sum(dmp.wart_nett) from Doc_Mag dmp
inner join mag_typ_doc mtd2 on dmp.typ_doc = mtd2.id
where mtd2.typ = 1
and dmp.status = 1
and dmp.id_mag = :mag
and extract(year from dmp.data_doc) = :y
and extract(month from dmp.data_doc)= :m
into :ss
do suspend
end