Subject Re: join aggregate query to table
Author Svein Erling Tysvær
I think there is something I don't see. To me, it looks like it should
simply be a minor change to your existing query:

select customer.name, sales.sales_id, sum(payments.allocated_amount)
from sales
join payments on sales.sales_id = payments.sales_id
join customer on sales.customer_id = customer.customer_id
group by customer.name, sales.sales_id

Maybe you would want to use LEFT JOIN rather than JOIN (in case some
sales doesn't include a customer). The only way this would fail is if
customer.customer_id is not unique.

HTH,
Set

-I support Firebird, I am a Firebird Foundation member!
-Join this weekend at the Firebird Conference in Prague:
http://www.ibphoenix.com/main.nfs?a=ibphoenix&s=1131440182:209405&page=fb_conference

--- In firebird-support@yahoogroups.com, "msarossy" wrote:
>
> i need some help with the sql to join an aggregate function to another
> table.
>
> the aggregate query :
>
> select sales.sales_id, sum(payments.allocated_amount)
> from sales join payments
> on sales.sales_id = payments.sales_id
> group by sales_id
>
> and then this needs to be joined by customer.customer_id to
> sales.customer_id
>
> your help is appreciated
>
> marko
>