Subject | Re: Optimizing a subquery |
---|---|
Author | kokok_kokok |
Post date | 2006-07-13T15:22:23Z |
Yes, it is correct, I need to show the percentage of sales over the
total of all customers.
Sales field is the total for one customer.
At the end, I want to show:
Customer Id
Customer Sales
% of Customer Sales / Total Sales for all customers
Thank you
total of all customers.
Sales field is the total for one customer.
At the end, I want to show:
Customer Id
Customer Sales
% of Customer Sales / Total Sales for all customers
Thank you
--- In firebird-support@yahoogroups.com, "Nick" <nick@...> wrote:
>
> > 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
> >
> >
> >
> >
> >
> >
> >
> >
>