Subject RE: [firebird-support] Optimizing a subquery
Author Nick
> select CustomerId, Sales, (select sum(Sales) from Customers)
> as Total from Customers

Are you sure this is correct, as written you would list each record and show
the same total on each record

select a.CustomerId, a.Sales, sum(b.Sales) as Total from Customers a inner
join customers b on a.custid = b.custid

Will list each sale for the customer and show the total for the customer on
each line as well


--
Nick
-----We Solve your Computer Problems---
UNIX, C, Panther, Ingres, Interbase, Firebird - Available Shortly

> -----Original Message-----
> From: firebird-support@yahoogroups.com
> [mailto:firebird-support@yahoogroups.com] On Behalf Of kokok_kokok
> Sent: 13 July 2006 13:34
> To: firebird-support@yahoogroups.com
> Subject: [firebird-support] Optimizing a subquery
>
>
>
>
> I need to do:
>
> select CustomerId, Sales, (select sum(Sales) from Customers)
> as Total from Customers
>
> It works fine, but for each row, Firebird executes the
> subquery "select sum(Sales) from Customers".
>
> Is there a way to optimize the plan?
>
> Thank you
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>