Subject | Re: Invalid expression in the select list (not contained in ..) FB problem? |
---|---|
Author | Pavle |
Post date | 2011-05-18T07:09:56Z |
--- In firebird-support@yahoogroups.com, "karolbieniaszewski" <liviuslivius@...> wrote:
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
>yes, same table (Doc_Mag), sorry... but there is no agregate function on DM level
>
> --- 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 ..
>
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