Subject Re: Optimizing a subquery
Author Ali Gökçen
Hi Mr. Kokok

--- In firebird-support@yahoogroups.com, "kokok_kokok"
<kokok_kokok@...> wrote:
>
> 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
>

You can't do it with a single query,
only redkit shoots before his shadow.

you need to calculete sum of sales before customer rows.

write a SP:

create procedure salesrates ..

returns customer_id ..., sales ..., total_sales ...

...

select sum(sales) from customers into :total_sales;

for select customer_id,sales from customers into :customer_id,:sales
do suspend;

end


thats all, you can use it in any reporter as a table:

select * from mysalesrates()

Ali
FFM#208