Subject Re: [firebird-support] Query Help
Author Anderson Farias
Hi,

This might work:

select A.CodeAg, T.Category, T.Target, sum(S.Amount)
from Agents A
left join target T on T.CodeAg=A.CodeAg
left join product P on P.category=T.category
left join sales S on S.productid=P.productid
-- some where clause
group by A.CodeAg, T.Category, T.Target


BUT, you can improve it by selecting from Sales and inner/lect join with
other tables, and you even won´t need table Agents participating. And also
with an WHERE clause on a indexed SALES field

HTH

Regards,
Anderson