Subject Re: [ib-support] Sum() on a subselect?
Author Arno Brinkman
Hi,

> Is it not possible to do a sum() on a subselect?

This isn't allowed in FB1.0 and your also using a field that's not part off
the GROUP BY clause, but FB1.5 will have this feature and then it should be
something like :

select
A.proddept,
count(*) as thecount,
sum(A.prodinventory) as theinv,
sum(A.prodprice*A.prodinventory) as price,
sum(vp.vpcost*A.prodinventory) as cost,
sum((select sum(fc.fifocost*fc.fifoqty) from fifocosts fc where
fc.fifobarcode=A.prodbarcode)) as paidcost
from
products A
left outer join vendorproducts vp on
vp.vpupc=A.prodbarcode and vp.vpvendor=A.prodsource
group by
A.proddept,
A.prodbarcode
order by
A.proddept


> I have the following query:
>
> select proddept,
> count(*) as thecount,sum(prodinventory) as theinv,
> sum(prodprice*prodinventory) as price,
> sum(vpcost*prodinventory) as cost,
> sum(select sum(fifocost*fifoqty) from fifocosts where
> fifobarcode=A.prodbarcode) as paidcost
> from products A left outer join vendorproducts on vpupc=prodbarcode and
> vpvendor=prodsource
> group by proddept
> order by proddept
>
> It's saying "Token Unknown" on the "select" in the 5th line.

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/


Nederlandse firebird nieuwsgroep :
news://80.126.130.81