Re: question about queries

From: Lun Wing San <wslun_at_qrcsun.qrc.org>
Date: 1996/11/19
Message-ID: <32921D6A.6BE7_at_qrcsun.qrc.org>#1/1


Jason Grace wrote:
>
> Lets say you have 3 tables, table A table B and table C.
>
> Say table A has info for different id's such as salary, name etc, on a
> one line per person basis. say for each line, there corresponds
> multiple lines in table B for that id, and similarly for table c.
>
> Now say tables A B and C have values valA, valB, and valC respectively
> as fields (for instance salary, payments), and I want to sum up these
> values for a given month.
>
> What is the fastest most efficient way to do this correctly?

  Suppose there are three tables: a, b, c.   The structure is a(i number , v number ), b(i number , v number ),   c(i number, v number). The distribution of the values is same as the   problem specified. You can solve your problem by using the following   query:

  select sum(a.v)/count(*), sum(b.v)/count(distinct(c.rowid)), sum(c.v)/count(distinct(b.rowid)) from a,b,c where a.i=b.i and b.i=c.i;

-- 
Name        : Lun Wing San
Title       : Oracle developer of the Hong Kong Productivity Council
              System Administrator and Oracle DBA of the Quick Response
Center
Email Addr. : sunny_at_hkpc.org
Telephone   : 852-2788-5841
Received on Tue Nov 19 1996 - 00:00:00 CET

Original text of this message